Sequential files: READ and WRITE
| OPEN and CLOSE | |
| READ AT END | |
| WRITE and REWRITE |
OPEN and CLOSE
OPEN prepares the file with a mode: INPUT for reading, OUTPUT for a new file, EXTEND to append, and I-O for update. CLOSE releases it:
OPEN INPUT EMPLOYEE-FILE.
CLOSE EMPLOYEE-FILE.
READ AT END
READ fetches the next record into the FD record area. AT END runs the end-of-file sentence, and NOT AT END runs when a record arrived. END-READ closes the scope:
READ EMPLOYEE-FILE
AT END MOVE "Y" TO WS-EOF
NOT AT END PERFORM PROCESS-ROW
END-READ.
WRITE and REWRITE
WRITE puts the record area into an OUTPUT or EXTEND file. On an I-O file, REWRITE replaces the record you last READ, and DELETE removes it:
OPEN OUTPUT EMPLOYEE-FILE.
MOVE "Ada Lovelace" TO EMP-NAME.
WRITE EMP-RECORD.
Next: Error handling: USE and DECLARATIVES
Article author: Arthur Isaev