COBOL Manual for TNS and TNS/R Programs
Procedure Division
HP COBOL Manual for TNS and TNS/R Programs—522555-006
8-40
Recovering from Input-Output Errors
At-End Condition or Invalid-Key Condition
If the error condition is the at-end condition or the invalid-key condition, the file is not
affected (that is, if the statement was an output statement, the contents of the file
remain unchanged). The run-time routines then perform these actions in this order:
1. If the statement that caused the condition includes any positive exception handling
phrase (AT END or INVALID KEY), transfer control to that phrase’s imperative
statement. Ignore any USE AFTER EXCEPTION procedure and any negative
exception handling phrases (NOT AT END, NOT INVALID KEY).
If control reaches the end of the AT END or INVALID KEY phrase, transfer control
to the statement immediately following the terminating period or scope terminator
of the I-O statement that caused the exception condition.
2. If the statement that caused the condition does not include a positive exception
handling phrase, but does include a negative exception handling phrase (NOT AT
END or NOT INVALID KEY), ignore any USE AFTER EXCEPTION procedure and
any negative exception handling phrases. Transfer control to the statement
immediately following the terminating period or scope terminator of the I-O
statement that caused the exception condition.
3. If all exception handling phases (AT END, NOT AT END, INVALID KEY, or NOT
INVALID KEY) are absent but a declarative procedure of the form USE AFTER
EXCEPTION is associated with the file, execute that procedure.
4. If control reaches the end of declarative procedure, transfer control to the
statement immediately following the terminating period or scope terminator of the
I-O statement that caused the exception condition.
5. If neither exception handling phrases nor declarative procedures apply, transfer
control to the statement immediately following the terminating period or scope
terminator of the I-O statement that caused the exception condition.
Other Error Conditions
If the execution is unsuccessful for a reason other than an at-end or invalid-key
condition, the behavior of the program depends on the presence or absence of a
declarative procedure for the file in question. If there is such a declarative procedure,
the behavior of the program also depends on the presence or absence of any negative
exception handling phrase (NOT AT END or NOT INVALID KEY).
When the run-time routines have recognized the exception condition, generated a run-
time diagnostic message, and stored the I-O status code, they take these actions in
this order:
1. If a declarative procedure of the form USE AFTER EXCEPTION is associated with
the file, execute the declarative procedure.
Then, if recovery from the exception is not possible (the I-O status code is “90” or
Status Key 1 is “4”), terminate the process.