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

Appendix A 215
COBOL Intrinsics
CKWRITE
CKWRITE
Procedure CKWRITE copies a logical record from the program's data area to an output or an
input/output KSAM file.
CALL "CKWRITE" USING
filetable, status, record, recordsize
A call to procedure CKWRITE may be used to write records to a KSAM file either in
sequential order or randomly by key value. The file must have been opened for output or
for input/output, but not for input only.
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 on the file was successful and if so what, it was.
status
One halfword (two 8-bit characters) set to a pair of values upon completion
of the call to CKWRITE to indicate whether or not the record was
successfully written and if not, why not.
record
A record defined in the WORKING-STORAGE SECTION containing data
to be written to the file by CKWRITE.
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, and it must be long enough to contain all
the keys.
Operation Notes
The file to which the content of
record
is written must be open for output only if
sequential mode is specified. It may be opened for output or input/output if the access
mode at open is random or dynamic.
When the file is opened for sequential access (access mode = 0) and for output only (I-O
type = 1), then records must be written to the file in ascending sequential order by primary
key value. The value of the primary key in the record to be written must be greater than
the value of the primary key in any record previously written to the file. This ensures that
the records written to the file are initially in ascending order physically as well as logically.
When I-O type = 1, CKWRITE writes records starting at the beginning of the file, thereby
effectively clearing any records previously written to the file.
In a file opened for random or dynamic access (access mode = 1 or 2) and for output only or
for input/output (I-O type = 1 or 2), records can be written in any order. The value of the
primary key need not be in any particular relation to the primary key values of previously
written records.
If you want to preserve existing records in the file, you should open the file with the
input/output type equal to 2; when input/output type = 1, all existing records are cleared
prior to the write.