Byte-stream File Routines

The byte-stream file routines enable you to read and write data files without the need to adhere to COBOL record definitions.

For all these routines, if the routine is successful the RETURN-CODE register is set to zero. If the routine fails, 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).

For this to work you should use RETURN-CODE and not have a RETURNING clause. If RETURN-CODE is nonzero after calling a byte-stream routine, move it to a PIC XX COMP-X data item to process it as a file status. For example:

 01 file-stat      pic xx comp-x.
 01    redefines file-stat.
     03 fs-byte-1  pic x.
     03 fs-byte-2  pic x comp-x.
   . . .
     call "CBL_xxx_FILE" using <parameters>
     if return-code not = 0
        move return-code to file-stat
           . . .

At this point fs-byte-1 contains "9" and fs-byte-2 contains the run-time system error number.