Summary -

In this topic, we described about the FILE Status Codes with detailed example.

The FILE STATUS clause allows naming a data item used in getting information about the success/failure of input-output operations performed on the file. When the FILE STATUS clause is specified, the system moves a value into the file-status-key data item after each input-output operation performed to the file.

file-status-key is the two-character data item named in the FILE STATUS clause. The value is placed in the file-status-key before execution of any EXCEPTION/ERROR declarative, INVALID KEY phrase or AT END phrase associated with the request.

This is a two-character data item with the first character known as file-status-key-1 and the second character known as file-status-key-2. The combinations of possible values and their meanings are shown in the below table.

High-order digit MeaningLow-order digit Meaning
0 Successful completion0 No further information
2 This file status value applies only to indexed files with alternate keys that allow duplicates.
The input-output statement was successfully executed, but a duplicate key was detected.
4 A READ statement was successfully executed. However, the length of the record being processed didn’t match to the fixed file attributes of the file.
5 An OPEN statement was successfully executed. However, the referenced optional file was unavailable at the time the OPEN statement was executed.
1 At-end condition0 A sequential READ statement was attempted and no next logical record existed in the file because the end of the file had been reached.
Or
The first READ was attempted on an optional input file that was unavailable.
4 A sequential READ statement was attempted for a relative file and the number of significant digits in the relative record number was larger than the size of the relative key data item defined for the file.
2 Invalid key condition1 A sequence error exists for a sequentially accessed indexed file. The prime record key value was changed by the program between the successful execution of a READ statement and the execution of the next REWRITE statement.
Or
The ascending requirements for successive record key values were violated.
2 An attempt was made to write a record that would create a duplicate key in a relative file.
Or
An attempt was made to write or rewrite a record that would create a duplicate prime record key or a duplicate alternate record key without the DUPLICATES phrase in an indexed file.
3 An attempt was made to randomly access a record that does not exist in the file.
Or
A START or random READ statement was attempted on an optional input file that was unavailable.
4 An attempt was made to write beyond the externally defined boundaries of a relative or indexed file.
Or
A sequential WRITE statement was attempted for a relative file and the number of significant digits in the relative record number was larger than the size of the relative key data item described for the file.
3 Permanent error condition3 An OPEN statement was unsuccessful because concatenated files were specified, but one or more of the requirements for concatenation were not satisfied. Possible violations are -
  • The file ORGANIZATION was not SEQUENTIAL.
  • The ACCESS MODE was not SEQUENTIAL.
  • The OPEN mode was not INPUT.
  • Too many file identifiers were specified in the concatenation or memory could not be obtained to record the file identifiers that were specified.
An OPEN or READ statement was unsuccessful because a nonoptional file in a concatenation was not available. For example, the file does not exist or user did not have sufficient access permissions.
4 An attempt was made to write beyond the externally defined boundaries of a sequential file.
5 An OPEN statement with the INPUT, I-O, or EXTEND phrase was attempted on a non-optional file that was unavailable.
7 An OPEN statement was attempted on a file that would not support the open-mode specified in the OPEN statement. Possible violations are -
  • The EXTEND or OUTPUT phrase was specified but the file would not support write operations.
  • The I-O phrase was specified but the file would not support the input and output operations.
  • The INPUT phrase was specified but the file would not support read operations.
8 An OPEN statement was attempted on a file previously closed with lock.
9 The OPEN statement was unsuccessful because a conflict was detected between the fixed file attributes and the attributes specified for that file in the program.
4 Logic error condition1 An OPEN statement was attempted for a file in the open mode.
2 A CLOSE statement was attempted for a file not in the open mode.
3 For a mass storage file in the sequential access mode, the last READ statement prior to the execution of a REWRITE statement was not successful.
For relative and indexed files in the sequential access mode, the READ statement prior to the execution of a DELETE or REWRITE statement was not successful.
4 An attempt was made to rewrite a record to a file and the record was not the same size as the record being replaced.
Or
An attempt was made to write or rewrite a record that was larger than the largest or smaller than the smallest record allowed by the RECORD IS VARYING clause of the associated file-name.
6 A sequential READ statement was attempted on a file open in the input or I-O mode and no valid next record had been established because -
  • The preceding READ statement was unsuccessful but did not cause an at-end condition.
  • The preceding READ statement caused an at-end condition.
7 A READ statement was attempted on a file not open in the input or I-O mode.
8 A WRITE statement was attempted on a file not open in the I-O, output or extend mode.
9 A DELETE or REWRITE statement was attempted on a file not open in the I-O mode.
9 Implementor-defined condition0 No further information
1 Authorization failure
2 Logic error
3 Resource unavailable
4 Concurrent open error
5 Invalid or incomplete file information
6 File system unavailable
8 Open failed due to locked file
9 Record access failed due to locked record