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

216 AppendixA
COBOL Intrinsics
CKWRITE
If the file was opened for shared access with CKOPENSHR, then you must lock the file with a
call to CKLOCK before writing any records. After the records are written, you should unlock
the file with a call to CKUNLOCK.
The invalid key condition (left byte of
status
=2) can occur as a result of the following
circumstances:
File was opened for sequential access in output mode and the value of the primary key
in the record being written is less than or equal to the value of the primary key in the
record just written;
status
=21.
File was opened for sequential or random access in output or input/output mode and the
value of the primary key is equal to the value of the primary key in an existing record;
status
=22.
File was opened for sequential or random access in output or input/output mode and the
value of an alternate key for which duplicates are prohibited equals the value of a
corresponding key in an existing record;
status
=22.
File was opened for sequential or random access in output or input/output mode and an
attempt was made to write a record beyond the physical bounds of the file;
status
=24.
Assume a KSAM file called KSAMFILE with records containing 74 characters, one primary
key containing a name, and an alternate key containing a phone number. The data is read
from an input file called DATA-FILE. (Refer to Figure A-2. for a diagram of the structure of
this file.)
The first example writes data to KSAMFILE in sequential order by the primary key.
DATA DIVISION
.
.
.
WORKING-STORAGE SECTION.
77 RECSIZE PIC S9(4) COMP VALUE 74.
77 RESULT PIC 9(4) VALUE 0.
01 REC.
03 FILLER PIC XX VALUE SPACES.
03 NAME PIC X(20).
03 PHONE PIC X(8).
03 OTHERDATA PIC X(44).
01 DAT.
03 NAME PIC X(20).
03 PHONE PIC X(8).
03 OTHERDATA PIC X(44).
01 FILETABLE.
03 FILENUMBER PIC S9(4) COMP VALUE 0.
03 FILENAME PIC X(8) VALUE "KSAMFILE".
03 I-O-TYPE PIC S9(4) COMP VALUE 0.
03 A-MODE PIC S9(4) COMP VALUE 0.
03 PREV-OP PIC S9(4) COMP VALUE 0.
01 STAT.
03 STATUS-KEY-1 PIC X.
03 STATUS-KEY-2 PIC X.
.
.