COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

NOTE: After an unsuccessful execution of a REWRITE statement, these values are
unpredictable:
The value of the file position indicator
The contents of the current record area
The key of reference
Any key value found in the current record area: that is, the value of the current key for indexed
files or the value of the alternate key for any type of file-system file, because in HP COBOL
sequential and relative files can have alternate keys.
The possible I-O status codes for an unsuccessful rewrite are:
Unsuccessful RewriteI-O Status Code
The file’s access mode is sequential, the file organization is indexed, and the prime record key
value of the logical record is not equal to the value of the prime record key of the last record
read. The invalid-key condition arises.
“21”
One of the alternate key values in the logical record is equal to the value of that key in a record
that already exists in the file, and the DUPLICATES phrase is not specified for that key. The
invalid-key condition arises.
“22”
The file’s access mode is random or dynamic, and the specified relative key value or prime
record key value does not correspond to that of any record existing in the file. The invalid-key
condition arises.
“23”
The rewrite operation failed due to non-COBOL causes. The specified record might or might
not have been rewritten. The run-time routines always return this status when the file is not
“30”
assigned to a disk, in which case nothing is rewritten. The value of the file position indicator
can be left undefined in some cases when the I-O status code is “30.
Whenever the rewrite operation terminates with an I-O status code greater than or equal to
“30,” execution of the REWRITE statement is unsuccessful. In this case, the applicable USE
procedure, if any, is executed.
The access mode is sequential, and the last input or output statement executed for the file was
not a successful READ statement. The record is not released.
“43”
There are two possibilities:“44”
The file is described with the RECORD VARYING clause, and the logical record size is greater
than the maximum or less than the minimum number of character positions specified in that
clause. The logical record is not released.
The file is a sequential file described with the RECORD VARYING clause, and the size of the
logical record is not equal to the size of the record being replaced. The logical record is not
released.
The file is not open in I-O mode. The rewrite operation terminates immediately.“49”
Access Mode and REWRITE
Sequential-access files
When a sequential file has variable-length records, the number of character positions in
the logical record specified by record-name must be equal to the number of character
positions in the record being replaced. If this is not so, the rewrite operation is unsuccessful
and terminates with I-O status code “44.
When the access mode of the file affected by the rewrite operation is sequential, the last
input-output statement executed for the file must have been a successful READ statement.
If it was not, the record is not released and the rewrite operation terminates with the I-O
status code “43;” otherwise, the rewrite operation logically replaces the record that was
426 Procedure Division Verbs