ILE COBOL Language Reference

REWRITE Statement Considerations

After a successful execution of a REWRITE statement, the record is no longer available in record-name-1 unless the associated file is named in a SAME RECORD AREA clause (in which case, the record is also available as a record of the other files named in the SAME RECORD AREA clause).

The file position indicator is not affected by execution of the REWRITE statement.

If the FILE STATUS clause is specified in the FILE-CONTROL entry, the associated status key is updated when the REWRITE statement is executed.

Sequential Files

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 INVALID KEY and NOT INVALID KEY phrases must not be specified. An EXCEPTION/ERROR procedure may be specified.

For files with sequential organization, the number of characters in record-name-1 must equal the number of character positions in the record being replaced.

Indexed Files

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.

+-------------------------------IBM Extension--------------------------------+

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.

Note:
The READ statement is required to ensure that the correct record is replaced when duplicate keys can be present in the file. The only way to rewrite one specific record from a sequence of records with duplicate keys is to read each of the records sequentially, and rewrite the required record when it has been identified.

+----------------------------End of IBM Extension----------------------------+

Relative Files

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 INVALID KEY and NOT INVALID KEY phrases must not be specified. An EXCEPTION/ERROR procedure may be specified.

If the access mode is random or dynamic, the record to be replaced is specified by the value in the RELATIVE 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 relative organization, the number of characters in record-name-1 can be different from the number of character positions in the record being replaced.

+-------------------------------IBM Extension--------------------------------+

Record Locking

A successful READ statement must precede any REWRITE statement for the following file types:

Such a READ statement must not include the NO LOCK phrase. If an attempt is made to replace a record that has been selected by a READ statement, and that record was not locked when it was read, the REWRITE statement will be unsuccessful.

+----------------------------End of IBM Extension----------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]