To replace a record in a file, use REWRITE if you opened the file for I-O. If the file was opened other than for I-O, the record is not replaced, and the status key is set to 49.
Check the file status key after each REWRITE statement.
For sequential files, the length of the replacement record must be the same as the length of the original record. For indexed files or variable-length relative files, you can change the length of the record you replace.
To replace a record randomly or dynamically, you do not have to first READ the record. Instead, locate the record you want to replace as follows:
related concepts
File organization and access mode
related tasks
Opening a file
Using file status keys
related references
FILE STATUS clause (COBOL for AIX Language Reference)