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, new records must be written in ascending key sequence. If the file is opened EXTEND, the record keys of the records to be added must be higher than the highest primary record key in the file when the file was opened.
For relative files, the records must be in sequence. If you include 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 data set for which you have coded ACCESS IS RANDOM or ACCESS IS DYNAMIC, you can write the records in any order.
related concepts
File organization and access mode
related tasks
Specifying a file organization and access mode
Using file status keys
related references
Statements used when writing records to a file
PROCEDURE DIVISION statements used to update files
FILE STATUS clause
(COBOL for Windows Language Reference)