COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
Usage Considerations:
• Action of the REWRITE Statement
The rewrite operation releases a logical record to the run-time routines as a replacement for
a record that exists in the file. The size of the logical record (the number of character positions
in the record) is determined:
◦ When the file has fixed length records (the file description entry includes a RECORD
CONTAINS n CHARACTERS, or contains no RECORD clause at all), the size of the logical
record is the fixed record size.
◦ When the file has variable-length records whose sizes are controlled by the DEPENDING
item specified in the RECORD clause (RECORD VARYING SIZE DEPENDING name), the
value of the DEPENDING item determines the size of the logical record.
◦ When the file has variable-length records but no DEPENDING item is specified in the
RECORD clause of the file description entry (RECORD CONTAINS m TO n CHARACTERS),
the size of the logical record is the size of the data item referenced by record-name.
If the data item has a variable size because it contains a table that is described with an
OCCURS DEPENDING clause, the current size of the item is used.
When the file is described with the RECORD VARYING clause, the logical record size must
not be greater than the maximum or less than the minimum number of character positions
specified in that clause. (See I-O status code “44.”)
The content of the logical record released by the rewrite operation is the left-justified value of
the data item specified by record-name. If the logical record size is greater than the data
item’s size, the value is logically extended on the right with arbitrary characters (that is, you
cannot predict what the extending characters will be). If the logical record size is less than
the data item’s size, the value is logically truncated on the right.
The execution of a REWRITE statement, whether successful or not, does not normally affect
the key of reference, the value of file position indicator, or the value of the depending item
specified in the DEPENDING phrase of the RECORD clause associated with record-name;
however, the value of the file position indicator can be left undefined in some cases when the
I-O status is set to 30.
NOTE: The logical record released by a successful execution of the REWRITE statement is
no longer available in the record area unless the file name associated with record-name is
specified in a SAME RECORD AREA clause. The logical record is available to the program
as a record of other files referenced in the SAME RECORD AREA clause as the associated
output file, as well as the file associated with record-name.
• File-Status Data Item
If the file has an associated file-status data item, execution of the REWRITE statement always
assigns an appropriate I-O status code as its value. The status “00” reports a successful rewrite
operation with no duplicate alternate keys written. The status code “02” reports a successful
rewrite operation that created a duplicate alternate key value for at least one alternate record
key for which duplicates are allowed (only when the file has the INSERTIONORDER attribute).
The rewrite operation cannot succeed if the device associated with the file is not a disk device.
REWRITE 425










