Writing to record I/O files

To write new records to a VSAM data set opened with type=record, use the Standard C fwrite() library function. If you set size to 1 and count to the desired record size, fwrite() returns the number of bytes written successfully. For more information on fwrite() and the type=record parameter, see z/OS XL C/C++ Runtime Library Reference.

In general, C I/O does not allow a write operation to follow a read operation without an intervening reposition or fflush(). z/OS® XL C/C++ counts a call to a write function writing 0 bytes or a write request that fails because of a system error as a write operation. However, z/OS XL C/C++ VSAM record I/O allows a write to directly follow a read. This feature has been provided for compatibility with earlier releases.

The process of writing to a data set for the first time is known as initial loading. Using the fwrite() function, you can write to a new VSAM file in initial load mode just as you would to a file not in initial load mode. Writing to a KSDS PATH or an ESDS PATH in initial load mode is not supported.

If your fwrite() call does not try to write more bytes than the maximum record size, fwrite() writes a record of the length you asked for and returns your request. If your fwrite() call asks for more than the maximum record size, fwrite() writes the maximum record size, sets errno, and returns the maximum record size. In either case, the next call to fwrite() writes to the following record.
Note: If an fwrite() fails, you must reposition the file before you try to read or write again.