Extended File Status Codes

The ANSI'74 and ANSI'85 file status conventions are augmented with extended file status codes. Extended file status codes have the character "9" as the first byte of the file status. The second byte is a binary (COMP-X) number, which is equivalent to a run-time system error number.

Extended file status codes are written as 9/nnn where nnn is the binary number in the second byte.

For example, if you are writing a file to disk and the disk runs out of space, the ANSI'74 file status would be a "30", which translates into the error message:

Permanent error - no other information is available

This error message is very general; a "permanent error" could mean that the disk has failed, or that the disk drive door is open. So, rather than return a generic file status, this COBOL system returns an extended file status of 9/007, that is, the character "9", in the first byte, and the binary value 7 in the second, meaning "disk full".

Note: A properly returned file status code should be of the form 9/nnn - for example 9/009.

If you are viewing this in HEX, the HEX value of the file status code might look like 3232. If you are viewing this in decimal mode, the same code will have a value of 12850. To retrieve the correct run-time system error when you are in decimal mode, you need to convert the decimal value to HEX first and then extract the correct error code.

For example, if you receive 14657 as a value for the file status, this is a decimal value. This converts to 3941HEX. The second byte of this value, 41, must be converted to Decimal before looking at the RTS error code - thus this HEX value then represents an extended file status code of 9/065 which means the error code is COBRT065, a locked file status.

When using ANSI'74 or ANSI'85 file status codes, the run-time system returns extended file status codes if the extended file status code is more specific.

The example code that follows illustrates how to redefine a standard file status so that it can be used as an extended file status. Assume for this example that the input file does not exist - when the OPEN INPUT statement is executed, a file status of 9/013 ("File not found") is returned.

     select in-file
         assign to "user.dat".
         file status is file-status.
        ...
 working-storage section.
 01 file-status.
     05 status-key-1             pic x.
     05 status-key-2             pic x.
     05 status-key-2-binary redefines status-key-2 
                                 pic 99 comp-x.
     ...
 procedure division.
     open input in-file
     if file-status not = "00"
         if status-key-1 = "9"
             if status-key-2-binary = 13
                 display "File not found"
        ...

To display the extended file status code, move the second byte of the file status data item to a display field large enough to hold the maximum value 255:

     select in-file
         assign to "user.dat"
         file status is file-status.
 ...
 working-storage section.
 01 ans74-file-status.
     05 status-key-1              pic x.
     05 status-key-2              pic x.
     05 status-key-2-binary redefines status-key-2 
                                  pic 99 comp-x.
 01 display-ext-status
     05 filler                    pic xx value "9/"
     05 display-key 2             pic 999
     ...
 procedure division.
     open input in-file
     if file-status not = "00"
         display "Error. File status =" with no advancing
         if status-key-1 = "9"
             move status-key-2-binary to display-key-2
             display display-ext-status
         else
             display file-status
         end-if
     end-if