REWRITE statement
The REWRITE statement logically replaces an existing record in a direct-access file. When the REWRITE statement is executed, the associated direct-access file must be open in I-O mode.
The REWRITE statement is not supported for line-sequential files.
- record-name-1
- Must be the name of a logical record in a DATA DIVISION FD entry. The record-name can be qualified.
- FROM phrase
- The result of the execution of the REWRITE statement
with the
FROM identifier-1 phrase is equivalent to the
execution of the following statements in the order specified.
MOVE identifier-1 TO record-name-1. REWRITE record-name-1
The MOVE is performed according to the rules for the MOVE statement without the CORRESPONDING phrase.
- identifier-1
- identifier-1 can reference one of the following items:
- A record description for another previously opened file
- An alphanumeric or national function
- A data item defined in the WORKING-STORAGE SECTION, the LOCAL-STORAGE SECTION, or the LINKAGE SECTION
identifier-1 must be a valid sending item with record-name-1 as the receiving item in accordance with the rules of the MOVE statement.
identifier-1 and record-name-1 must not refer to the same storage area.
After the REWRITE statement is executed, the information is still available in identifier-1 (INTO and FROM phrases under "Common processing facilities").
INVALID KEY phrases
An INVALID KEY condition exists when:
- The access mode is sequential, and the value contained in the prime RECORD KEY of the record to be replaced does not equal the value of the prime RECORD KEY data item of the last-retrieved record from the file
- The value contained in the prime RECORD KEY does not equal that of any record in the file
- The value of an ALTERNATE RECORD KEY data item for which DUPLICATES is not specified is equal to that of a record already in the file
For details of invalid key processing, see Invalid key condition.
END-REWRITE phrase
This explicit scope terminator serves to delimit the scope of the REWRITE statement. END-REWRITE permits a conditional REWRITE statement to be nested in another conditional statement. END-REWRITE can also be used with an imperative REWRITE statement.
For more information, see Delimited scope statements.