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

Appendix A 205
COBOL Intrinsics
CKREWRITE
CKREWRITE
The procedure CKREWRITE replaces a record existing in a KSAM file with another record
having a matching primary key.
CALL "CKREWRITE" USING
filetable, status, record, recordsize
You can replace an existing record in a KSAM file with the procedure CKREWRITE. This
procedure replaces a record previously read from the file with another record whose
primary key matches the primary key of the record being replaced.
Parameters
filetable
An 8 halfword record containing the number and name of the file, its
input/output type, access mode, and a code indicating whether the
previous operation was unsuccessful and if so what it was.
status
One halfword (two 8-bit characters) set to a pair of values upon the
completion of the call to CKREWRITE indicating whether or not the call was
successful and if not why not. (Refer to Status Parameter discussion
earlier in this section.)
record
A record defined in the WORKING-STORAGE SECTION containing data
to be written as a logical record to the file replacing the record with a
matching primary key.
recordsize
An integer (S9(4)COMP) containing the length in characters of the record
to be written. It must not exceed the maximum record length established
for the file when it was created.
Operation Notes
In order to call procedure CKREWRITE, the file must be open for both input and output
(input/output type=2). The access mode can be sequential, random, or dynamic. If access
mode is sequential, CKREAD must have been executed successfully just prior to the call to
CKREWRITE. In random or dynamic mode, no prior read is required; the system searches the
file for the record to be rewritten.
When the file is opened in sequential mode (access mode = 0), CKREAD must be executed
before CKREWRITE. The primary key in the record to be written by CKREWRITE must be
identical to the primary key in the record read by CKREAD. A simple way to ensure that the
keys match is to read a record into WORKING-STORAGE, modify it without altering the
primary key, and then write it back to the file using CKREWRITE. Since the primary key is
not changed, the sequence of records in the file is not affected.
If you want to rewrite in sequential mode all the records in a chain of records with
duplicate keys, use either CKSTART or CKREADBYKEY to position to the first record in the
chain. Then call CKREWRITE to update the first record in the chain. Subsequent calls
depend on whether you are changing any key value in the record (not necessarily the
selected key).