Each file-control entry can include a FILE STATUS clause that designates a 2-character file-status data item declared elsewhere in the program as the receptacle for that file’s I-O status code. The leftmost character position of the file-status data item is Status
Key 1. The rightmost character position of the file-status data item is Status Key 2.
Whenever a program executes a CLOSE, DELETE, LOCKFILE, OPEN, READ, REWRITE, START, UNLOCKFILE, UNLOCKRECORD, or WRITE statement for a file that has a FILE STATUS clause, the COBOL run-time routines record the I-O status code in the specified file-status data item. The storage operation occurs prior to the execution of any applicable USE procedure or any applicable imperative statement
associated with the input-output statement (in AT END, NOT AT END, INVALID KEY, or NOT INVALID KEY phrases).
The I-O status code indicates the success or failure of the input-output statement, and (if failure), the reason for the failure. Check your COBOL manual for the meanings of each Status Key value.
Example:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE-1
ASSIGN TO “NAMEFILE1"
FILE STATUS IS FILE-STATUS.
SELECT IN-FILE-2
ASSIGN TO “NAMEFILE2"
FILE STATUS IS FILE-STATUS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 FILE-STATUS PIC X(02).
88 NO-ERRORS VALUE “00”.
88 END-OF-FILE VALUE “10”.
ETC…
PROCEDURE DIVISION.
DECLARATIVES.
IN-FILE-1 SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON IN-FILE-1.
PARA-1.
IF NOT END-OF-FILE
SET FILE-1-ERROR TO TRUE
END-IF.
IN-FILE-2 SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON IN-FILE-2.
PARA-2.
IF NOT END-OF-FILE
SET FILE-2-ERROR TO TRUE
END-IF.
...
END DECLARATIVES.