INVALID KEY Condition
The invalid key condition can occur during execution of a START, READ, WRITE, REWRITE, or DELETE statement.
(For details of the causes for the condition, see the appropriate
statement in Procedure Division Statements.) When an invalid
key condition occurs, the input-output statement that caused the condition
is unsuccessful. When the invalid key condition exists after an input-output
operation, the following actions are taken:
- If there is an applicable file status clause (but not an applicable USE procedure), the file status is updated, and control returns to the program.
- Control will be transferred to the imperative statement of an INVALID KEY phrase, if specified.
- If an explicit or implicit EXCEPTION/ERROR procedure is specified for the file, the procedure runs; if no such procedure is specified, the results are unpredictable.
- In the absence of a file status clause, USE procedure, or INVALID KEY phrase to handle the error, a run-time message is issued, giving you the option to end or return to the program.
When the invalid key condition does not exist after an input-output
operation, the INVALID KEY phrase is ignored, if specified, and the
following actions are taken:
- If an exception condition that is not an invalid key condition exists, control is transferred according to the rules of the USE statement following the running of any USE AFTER EXCEPTION procedure.
- If no exception condition exists, control is transferred to the end of the input-output statement or the imperative statement specified in the NOT INVALID KEY phrase, if it is specified.
For more information about error handling and the role of the INVALID KEY phrase, see the chapter on exception and error handling in the IBM® Rational® Development Studio for i: ILE COBOL Programmer's Guide.