Using KSAM/XL and KSAM 64 (32650-90886)

56 Chapter6
Writing and Updating Record Data
Writing New Records
Writing New Records
The FWRITE intrinsic writes new records to a new or existing file from a buffer in your
program. Index entries for primary and alternate keys are entered automatically for each
record written.
Depending on how the file was created, records may be written in random or sequential
order. If the REUSE option is specified, each record is written to the next available space. If
the NOREUSE option is specified, all records are written at the end of the file.
Records written to an existing file either overwrite existing records or are appended to
existing records. This is determined by the access option of the
aoptions
parameter,
selected in the HPFOPEN or FOPEN intrinsic call.
Following each write procedure, the logical record pointer is positioned at the next
sequential record in key sequence or at the end-of-file marker. When the physical bounds
of either the data area or index area of the file is reached, a CCG condition code is returned
to your program.
Note that the control parameter of the FWRITE intrinsic must be included in the intrinsic
call for compatibility. It has no meaning for KSAM files.
When writing records to a file that has shared access, file locking should be used. The
HPFOPEN or FOPEN intrinsic call must allow dynamic locking. An FLOCK intrinsic should be
included before pointers are positioned and records are written. Unlock the file using the
FUNLOCK intrinsic when the write procedure is complete.
Updating Existing Records
To update a record in a KSAM file, the HPFOPEN or FOPEN intrinsic call to open the file
must specify update access. This is set by the
aoption
parameter. Normally, you would
read the record with one of the read intrinsics , to verify its contents before modification.
The FUPDATE intrinsic writes the contents of the buffer area over the contents of the last
record accessed. This buffer area is identified in an FUPDATE intrinsic parameter. The
written record must contain all the key values expected by the file. If only a portion of the
record is updated, specified by the
tcount
parameter, this portion must contain all
primary and alternate key values. If it does not, a CCL condition is returned and the
update does not take place.