Adding records to a file

The COBOL WRITE statement adds a record to a file without replacing any existing records. The record to be added must not be larger than the maximum record size set when the file was defined. Check the file status key after each WRITE statement.

Adding records sequentially: To add records sequentially to the end of a file that has been opened with either OUTPUT or EXTEND, use ACCESS IS SEQUENTIAL and code the WRITE statement.

Sequential and line-sequential files are always written sequentially.

For indexed files, you must add new records in ascending key sequence. If a file is opened EXTEND, the record keys of the records to be added must be higher than the highest primary record key that was in the file when it was opened.

For relative files, the records must be in sequence. If you code a RELATIVE KEY data item in the SELECT clause, the relative record number of the record to be written is placed in that data item.

Adding records randomly or dynamically: When you write records to an indexed file for which you coded ACCESS IS RANDOM or ACCESS IS DYNAMIC, you can write the records in any order.

related concepts  
File organization and access mode