Previous Topic Next topic Print topic


Example of Extended File Status Codes

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"
  ...

If you want to display the extended file status code, you need to 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
  ...
Previous Topic Next topic Print topic