Opening a file

Before your program can use a WRITE, START, READ, REWRITE, or DELETE statement to process records in a file, the program must first open the file using an OPEN statement.

PROCEDURE DIVISION.
    . . .
    OPEN iomode filename

In the example above, iomode specifies the open mode. If you are only reading from the file, code INPUT for the open mode. If you are only writing to the file, code either OUTPUT (to open a new file or write over an existing one) or EXTEND (to add records to the end of the file) for the open mode.

To open a file that already contains records, use OPEN INPUT, OPEN I-O (not valid for line-sequential files), or OPEN EXTEND.

If you code OPEN OUTPUT for either an SdU or SFS file that contains records, the COBOL run time deletes the file and then creates the file with attributes provided by COBOL. If you do not want an SdU or SFS file to be deleted, open the file by coding OPEN I-O instead.

If you open a sequential, line-sequential, or relative file as EXTEND, the added records are placed after the last existing record in the file. If you open an indexed file as EXTEND, each record that you add must have a record key that is higher than the highest record in the file.

related concepts  
File organization and access mode  

related tasks  
Opening optional files