Handling errors in input and output operations
When an input or output operation fails, COBOL does not automatically take corrective action. You choose whether your program will continue running after a less-than-severe input or output error.
About this task
You can use any of the following techniques for intercepting and handling certain input or output conditions or errors:
- End-of-file condition (
AT END) ERRORdeclarativesFILE STATUSclause and file status key- File system status code
- Imperative-statement phrases in
READorWRITEstatementsFor VSAM files, if you specify a
FILE STATUSclause, you can also test the VSAM status code to direct your program to error-handling logic. INVALID KEYphrase
To have your program continue, you must code the appropriate error-recovery procedure. You might code, for example, a procedure to check the value of the file status key. If you do not handle an input or output error in any of these ways, a severity-3 Language Environment® condition is signaled, which causes the run unit to end if the condition is not handled.
The following figure shows the flow of logic after a VSAM input or output error:
The following
figure shows the flow of logic after an input or output error with
QSAM or line-sequential files. The error can be from a READ statement,
a WRITE statement, or a CLOSE statement
with a REEL/UNIT clause (QSAM only).
*Possible
phrases for QSAM are AT END, AT END-OF-PAGE,
and INVALID KEY; for line sequential, AT
END.
**You need to write the code to test the file status key.
***Execution of your COBOL program continues after the input or output statement that caused the error.


