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.

CBL_CLOSE_FILE Close byte-stream file
CBL_CREATE_FILE Create byte-stream file
CBL_FLUSH_FILE Flush byte-stream file buffers to disk
CBL_FREE_RECORD_LOCK Release a record lock on a file
CBL_GET_RECORD_LOCK Obtain a record lock on a file
CBL_OPEN_FILE Open byte-stream file
CBL_READ_FILE Read byte-stream file
CBL_TEST_RECORD_LOCK Obtain a record lock on a file
CBL_WRITE_FILE Write byte-stream file

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.

Byte-stream File Handling Routines - Example

Related Topics: