Interpreting the Return Code as a File Status Code

If any of the routines fail, the RETURN-CODE register contains a file status value indicating the failure:

This file status is always the standard ANSI'74 file status value. If no ANSI'74 file status is defined for the error, an extended file status is returned (9/nnn where nnn is the run-time system error number).

You should, therefore, use RETURN-CODE and not a RETURNING clause. If RETURN-CODE is non-zero after calling one of these routines, you must process it as a file status; for example, the follow excerpt attempts to delete a non-existent file:

       copy cbltypes.cpy.
       01 file-status      pic xx comp-x. 
       01 redefines file-status. 
          03 fs-byte-1  pic x. 
          03 fs-byte-2  cblt-x1-compx.
       call "CBL_DELETE_FILE" using "c:\nonexistfile.txt". 
          if return-code not = 0 
            move return-code to file-status 
          end-if.
	      display "return-code = " return-code.
          display "fs-byte-1 = " fs-byte-1.
          display "fs-byte-2 = " fs-byte-2.
          display "which equates to COBRT013 File Not Found".

The resulting file-status produces fs-byte-1 containing "9" (to indicate an extended file status code), and fs-byte-2 contains "013", which equates to the run-time system error COBRT013 File Not Found.