COBOL File Processing

COBOL file processing refers to the operations carried out on data files, like reading, writing, updating, and deleting records.

When writing a COBOL program, it's important to choose the appropriate file processing method based on the nature of the data and the operations that will be performed on it.

Below are the file processing statements -

StatementDescription
OPEN File Detailed Tutorial    OPEN statement establishes a connection between the logical file and its associated physical file. It opens the file for subsequent processing (e.g., reading, writing, updating).
READ Statement Detailed Tutorial    READ statement is used to retrieve a record from the file. At a time, only one record is retrieved from the file.
WRITE Statement Detailed Tutorial    WRITE statement is used to add a record to the file. At a time, only one record is written to the file.
REWRITE Statement Detailed Tutorial    REWRITE statement is used to replace the content of a previously read record with new data. At a time, only one record is replaced in the file.
DELETE Statement Detailed Tutorial    DELETE statement removes a record from an indexed or relative file. After the successful execution of a DELETE statement, the record is removed from the file and can no longer be available.
START Statement Detailed Tutorial    START is used to set the file pointer to read the record. It won't retrieve any record and only sets the pointer before beginning a sequence of READ operations.
READ NEXT Statement Detailed Tutorial    READ NEXT statement is used to read the next record from the current reading position of the file. At a time, only one record is retrieved from the file.
CLOSE Statement Detailed Tutorial    CLOSE statement is used to terminate the file processing and release the resources of the file.