I-O Status

If the FILE STATUS clause is specified in a file control entry, a value is placed into the specified two-character data item during the execution of an OPEN, CLOSE, READ, WRITE, REWRITE, DELETE, UNLOCK or START statement before any applicable USE procedure is executed, to indicate the status of that input-output operation.

The file status keys described in the following pages are for those files which conform fully to the ANSI standard and which use none of the extensions available with this COBOL system.

MFUse of extensions, for example, specifying a file as LINE SEQUENTIAL, affects the status keys returned. Additional information is provided under the relevant verbs.

Status Key 1

The leftmost character position of the FILE STATUS data item is known as status key 1 and is set to indicate one of the following conditions upon completion of the input-output operation on a file of any organization.

"0" - Successful completion
"1" - At end
"2" - Invalid key
"3" - Permanent error
ANS85 "4" - Logic error
"9" - Run-time system error message

The meaning of the above conditions is as follows:

"0" Successful completion. The input-output statement was successfully executed.
"1" At end. The sequential READ statement was unsuccessfully executed either because of an attempt to read a record when no next logical record exists in the file or because the first READ statement was executed for a file described with the OPTIONAL clause when that file was not available at the time its associated OPEN statement was executed.
"2" Invalid key. The input-output statement on a non-sequential file was unsuccessfully executed because of one of the following:

Sequence error Duplicate key No record found Boundary violation

"3" Permanent error. The input-output statement was unsuccessfully executed because of a boundary violation for a sequential file or because of an input-output error, such as a data check parity error or transmission error.
ANS85"4" Logic error. The input-output statement was unsuccessfully executed, either because an improper sequence of input-output operations was performed on the file, or because a limit you defined was violated.
"9" Run-time system error message. The input-output statement was unsuccessfully executed because of a condition that is specified by the run-time system error message number. This value is used only to indicate a condition not indicated by other defined values of status key 1, or by specified combinations of the values of status key 1 and status key 2.

Status Key 2

The rightmost character position of the FILE STATUS data item is known as status key 2 and is used to further describe the results of the input-output operation.

The combination of status key 1 and status key 2 defines the result of the input-output operation as detailed below.

Successful Completion

If status key 1 contains "0" to indicate the successful completion of the input-output operation, status key 2 can contain one of the following values:

"0" (all files) No further information is available
"2" (indexed files only) Indicates one of two possibilities:
  • For a READ statement, the key value for the current key of reference is equal to the value of the same key in the next record within 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.
ANS85"4" (all files) Indicates that the length of the record being processed does not conform to the fixed file attributes for that file.
ANS85"5" (all files) Indicates that the referenced optional file was not present at the time the OPEN statement was executed.
ANS85"7" (record sequential files only) Indicates that for a CLOSE statement with the NO REWIND, REEL/UNIT or FOR REWIND phrase, or an OPEN statement with the NO REWIND phrase, the referenced file is a non-reel/unit medium.

AT END Condition with Unsuccessful Completion

If status key 1 contains "1" to indicate the AT END condition, status key 2 can contain one of the following values:

"0" (all files) Indicates that there is no next logical record. This can be caused by two conditions:
  • The end of the file has been reached.
  • A sequential READ statement has been attempted for the first time on an optional input file that is not present.
ANS85"4" (relative files only) Indicates that the number of significant digits in the relative record number is larger than the size of the relative key data item described for that file.

INVALID KEY Condition with Unsuccessful Completion

If status key 1 contains "2" to indicate INVALID KEY condition, status key 2 indicates the cause of the condition by one of the values:

"1" (sequentially accessed indexed files) Indicates a sequence error. The ascending sequence requirements of successive record key values have been violated (see the topic The WRITE Statement), or the prime record key value has been changed by the COBOL runtime element between the successful execution of a READ statement and the execution of the next REWRITE statement for that file.
"2" (relative and indexed files only) Indicates a duplicate key value. An attempt has been made either to write a record that would create a duplicate prime record key or to write or rewrite a record that would create a duplicate alternate record key when the DUPLICATES phrase is not specified for that alternate record key.
"3" (relative and indexed files only) Indicates no record found. An attempt has been made to access a record, identified by a key, and that record does not exist in the file, or a START or READ statement has been attempted on an optional input file that is not present.
ANS85"4" (relative and indexed files only) Indicates a boundary violation arising from one of the following conditions:
  • An attempt has been made to write beyond the externally defined boundaries of a file.
  • A sequential WRITE statement has been attempted for a relative file, but the number of significant digits in the relative record number is larger than the size of the relative key data item described for the file.

Permanent Error Condition with Unsuccessful Completion

If status key 1 contains "3" to indicate a permanent error condition, status key 2 can contain one of the following values to indicate the cause of that error:

"0" (all files) Indicates that no further information is available concerning the cause of the error.
"4" (sequential files only) Indicates a boundary violation. An attempt has been made to write beyond the externally defined boundaries of a file.
ANS85"5" (all files) Indicates that an OPEN statement with the INPUT, I-O, or EXTEND phrase has been attempted on a non-optional file that is not present.
ANS85"7" (all files) Indicates that an OPEN statement has been attempted on a file which does not support the open mode specified in the OPEN statement. The possible violations are:
  • The EXTEND or OUTPUT phrase has been specified but the file does not support write operations.
  • The I-O phrase has been specified but the file doesl not support the input and output operations that are permitted for a relative file when opened in the I-O mode.
  • The INPUT phrase has been specified but the file does not support read operations.
ANS85"8" (all files) Indicates that an OPEN statement has been attempted on a file previously closed with lock.
ANS85"9" (record sequential, relative and indexed files) Indicates that a conflict has been detected between the fixed file attributes and the attributes specified for that file in the source element.

ANS85 Logic Error Condition with Unsuccessful Completion

If status key 1 contains "4" to indicate a logic error condition, status key 2 can contain one of the following values to indicate the cause of that error:

"1" (all files) Indicates that an OPEN statement has been attempted for a file already in open mode.
"2" (all files) Indicates that a CLOSE statement has been attempted for a file not in open mode.
"3" (all files, sequential access mode only) Indicates that the last input-output statement executed for the associated file, prior to the execution of a DELETE or REWRITE statement, was not a successfully executed READ statement.
"4" (record sequential files only) Indicates that a boundary violation exists. A possible violation is that an attempt has been made to WRITE or REWRITE a record that is larger than the largest, or smaller than the smallest, record allowed by the RECORD IS VARYING clause of the associated file.
"5" (all files ) An attempt has been made to REWRITE a record to a file, and the record is not the same size as the record being replaced.

MFFor line sequential files this refers to the physical size of the record, that is after space removal, tab compression and null insertion. In this case, the physical size of the new record is allowed to be smaller than that of the record being replaced.

"6" (all files) Indicates that a sequential READ statement has been attempted on a file open in input or I-O mode, but no valid next record has been established. This can be caused by the following conditions:
  • The preceding START statement was unsuccessful.
  • The preceding READ statement was unsuccessful but did not cause an at end condition.
  • The preceding READ statement caused an at end condition.
"7" (all files) Indicates that the execution of a READ or START statement has been attempted on a file not open in input or I-O mode.
"8" (all files) Indicates that the execution of a WRITE statement has been attempted on a file not open in I-O, output or extend mode, or on a file open I-O in sequential access mode.
"9" (all files) Indicates that the execution of a DELETE or REWRITE statement has been attempted on a file not open in I-O mode.

MF Run-Time System Error Message

If status key 1 contains " 9" to indicate a run-time system error message, status key 2 contains the run-time system error message number in binary. These are described in full in your COBOL system documentation.

Valid Combinations of Status Keys 1 And 2

In the following table: "S" indicates a Record Sequential file,

MF "L " indicates a Line Sequential file,

"R" indicates a Relative file and "I" indicates an Indexed file.

A particular combination of status key 1 and status key 2 is valid for a given file organization if the letter for that organization is found at the corresponding intersection in Table 1.

Status Key 1 Status Key 2
0 1 2 3 4 5 6 7 8 9
Successful Completion 0 SRIL   I   SRIL SRIL   S    
At End 1 SRIL       R          
Invalid Key 2   I RI RI RI          
Permanent Error 3 SRIL       SL SRIL   SRIL SRIL SRI
Logic Error 4   SRIL SRIL SRIL SRIL   SRIL SRIL SRIL SRIL
Implementor Defined 9 Run-Time System Error Message (SRIL)
Table 1: Valid Combinations of Status Keys 1 and 2