COBOL File Status Codes

After each input or output statement is performed on a file, the system updates values in the two digit positions of the file status key. In general, a zero in the first position indicates a successful operation, and a zero in both positions means that nothing abnormal occurred.
Establish a file status key by coding:

The FILE STATUS clause in the FILE-CONTROL paragraph:

CODE: Select all

FILE STATUS IS data-name-1
Data definitions in the DATA DIVISION (WORKING-STORAGE, LOCAL-STORAGE, or LINKAGE SECTION), for example:

CODE: Select all

WORKING-STORAGE SECTION.
01  data-name-1  PIC 9(2)  USAGE NATIONAL.
Specify the file status key data-name-1 as a two-character category alphanumeric or category national item, or as a two-digit zoned decimal or national decimal item. This data-name-1 cannot be variably located.


Status Description
00 Successful completion
02 Indexed files only. Possible causes:
For a READ statement the key value for the current key is equal to the value of that same key in the next record in the current key of reference.
For a WRITE or REWRITE statement the record just written created a duplicate key value for at least one alternate record key for which duplicates are
allowed.

Status Key Values and Meanings
Code High Order Digit Meaning Low Order Digit Meaning
00 0 Successful Completion 0 No further information
02 0 2 The input-output statement was successfully executed, but a duplicate key was detected. For a READ statement the key value for the current key of reference was equal to the value of the same key in the next record within the current key of reference. For a REWRITE or WRITE statement, the
record just written created a duplicate key value for at least one alternate record key for which duplicates are allowed.
04 0 4 A READ statement was successfully executed, but the length of the record being processed did not conform to the fixed file attributes for that file.
Text14 Text24 Text34 Text44
Text15 Text25 Text35 Text45