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

196 AppendixA
COBOL Intrinsics
CKOPEN
mode; you may call CKREADBYKEY, CKWRITE, CKREWRITE, or CKDELETE (but not CKREAD or
CKSTART) when opened in random mode. In dynamic mode, any of the KSAM procedures
may be called. With this type of input/output, existing records are not cleared when you
write a record with CKWRITE.
Halfword 7 of
filetable
must be set to one of the following values before calling CKOPEN:
0 sequential access
1 random access
2 dynamic access
With sequential access, records in the file are read in ascending order based on the value of
a key within each record. The key is the primary key unless an alternate key was specified
with CKSTART. Reading starts with the first record in sequence unless a particular record
was specified with CKSTART. Each time a call to CKREAD is executed, the next record in
sequence is read from the file. CKREAD and CKSTART are the only procedures that can be
called in input mode. CKREADBYKEY cannot be specified for any input/output type if the
access mode is sequential.
In output mode, CKWRITE is the only procedure that can be called. When access is
sequential, the record to be written must contain a unique primary key that is greater in
value than the key of any previously written record. If it is not in sequence, an invalid key
sequence error 21 is returned to
status
.
In input/output mode, CKREWRITE and CKDELETE can be specified as well as CKREAD and
CKSTART, but CKWRITE cannot.
Random access allows you to read, write, replace, or delete a record with any value for its
primary key. To read a record, the CKREADBYKEY procedure must be called in either input or
input/output mode. CKREAD and CKSTART cannot be specified for any input/output type
when access mode is random.
When writing a record with CKWRITE in output or input/output mode, the value of the
primary key in the record need not be greater than the keys of previously written records;
that is, records can be written in any order.
In input/output mode, CKREWRITE can be used to replace any record whose primary key
matches the primary key in the record being written. CKDELETE can be used to delete a
record specified in a previous CKREADBYKEY call.
CKWRITE can be used to write a record following existing records in the file if you position to
follow the last sequential record before writing. Use this input/output type if you want to
save existing data in a file to which you are writing.
Dynamic access allows you to use any call to process a file opened for input/output. When
the file is opened in dynamic mode, and a call is made to CKREAD or CKSTART, the file can be
read, but not updated, sequentially. For all other calls, dynamic mode is treated as if the
file had been opened in random mode. The reason to open a file in dynamic mode is to allow
both sequential and random processing on the same file without closing it and then
opening it again each time access switches from sequential to random or vice versa.
To open a file initially for sequential read: