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.
Records are written to the cluster according to the value stored in the field designated as the prime key.
You can load a KSDS in any key order but it is most efficient to perform the fwrite() operations in key sequence.
Records are written to the end of the file.
Records are written according to the value stored in the relative record number field.
fwrite() is called with the RRDS record structure.
By default, in record mode, fwrite() and fupdate() must be called with a pointer to an RRDS record structure. The __rrds_key_type fields __fill and __recnum must be set. __fill is set to 0 or 1 to indicate the type of the structure. The __recnum field specifies the RRN to write, and is required for fwrite() but not fupdate(). The count argument must include the length of the __rrds_key_type. fwrite() and fupdate() include the length of the __rrds_key_type in the return value.