If the access mode is sequential, the last input/output statement that was executed for the file must have been a successful READ statement. The record to be replaced is the record that was retrieved by that statement. The value of the RECORD KEY data-item must not have been changed since the record was read. If the value has been changed, then an INVALID KEY condition exists.
If the access mode is random or dynamic, the record to be replaced is specified by the value in the RECORD KEY data-item. If the file does not contain such a record, then an INVALID KEY condition exists.
An INVALID KEY phrase should be specified if no EXCEPTION/ERROR procedure has been defined for the file.
For files with indexed organization, the number of characters in record-name-1 can be different from the number of character positions in the record being replaced.
When EXTERNALLY-DESCRIBED-KEY is specified for the file, the key data held in the record area that corresponds to the format specified by the FORMAT phrase (or to the first format, if the FORMAT phrase is not used) is used to determine the current value of the RECORD KEY data-item.
When the WITH DUPLICATES phrase is specified for the file, then for all access modes (sequential, random, and dynamic) the last input/output statement that was executed for the file must have been a successful READ statement. The record to be replaced is the record that was retrieved by that statement. The value of the RECORD KEY data-item must not have been changed since the record was read. If the value has been changed, then an INVALID KEY condition exists.