COBOL Manual for TNS and TNS/R Programs

Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs522555-006
9-207
REWRITE for Sequential, Relative, Indexed, and
Queue Files
UNLOCK Phrase
If the UNLOCK phrase appears, the rewrite operation also assures that the record
is not in the locked state at the completion of the rewrite operation. If the record
was not in the locked state at the beginning of the rewrite operation, no report of
this is made to the program.
Invalid-Key Condition
Any of these circumstances can lead to an invalid-key condition:
°
The 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. This results in a completion status of 21.
°
The 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. This results in I-O status code “23.
°
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. This results in an I-O status code of “22.”
When the invalid-key condition exists, the rewrite operation does not occur and
execution of the REWRITE statement is unsuccessful. The content of the record
area is unaffected. If the INVALID KEY phrase is specified, control passes to the
imperative statement in that phrase and no USE procedure is executed. If the
INVALID KEY phrase is not specified but an applicable USE procedure exists, that
procedure is executed.
When the invalid-key condition does not exist, and the rewrite operation is
successful, and the NOT INVALID KEY phrase is specified, control passes to the
imperative statement in that phrase.
Example 9-61. REWRITE Statement for Indexed File
READ MASTER-IN WITH LOCK
IF NO-ERROR
PERFORM GET-INPUT
REWRITE MASTER-RECORD WITH UNLOCK
IF NO-ERROR
ADD 1 TO UPDATE-COUNTER
ELSE UNLOCKRECORD MASTER-IN
END-IF
ELSE
...
Note. Invalid-key conditions are taken care of by USE procedures instead of by INVALID KEY
phrases on the READ and REWRITE statements.