Reading record I/O files

To read from a VSAM data set opened with type=record, use the Standard C fread() library function. If you set the size argument to 1 and the count argument to the maximum record size, fread() returns the number of bytes read successfully. For more information on fread(), see z/OS XL C/C++ Runtime Library Reference.

fread() reads one record from the system from the current file position. Thus, if you want to read a certain record, you can call flocate() to position the file pointer to point to it; the subsequent call to fread() reads in that record.

If you use an fread() call to request more bytes than the record about to be read contains, fread() reads the entire record and returns the number of bytes read. If you use fread() to request fewer bytes than the record about to read contains, fread() reads the number of bytes that you specified and returns your request.

z/OS® XL C/C++ VSAM Record I/O does not allow a read operation to immediately follow a write operation without an intervening reposition. z/OS XL C/C++ treats the following as read operations:
Calling fread() several times in succession, with no other operations on this file in between, reads several records in sequence (sequential processing), which can be forward or backward, depending on the access direction, as described in the following.