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

Appendix A 203
COBOL Intrinsics
CKREADBYKEY
In order to delete records in random or dynamic mode, CKREADBYKEY must be called before
executing CKDELETE. It is not required prior to CKREWRITE.
In the following examples, update information is read into the area called DAT in the
WORKING-STORAGE SECTION. (Note that in this as in the preceding examples, the
WORKING-STORAGE SECTION from Figure A-2. continues to be useful.) In the first
example, the primary keys of records in KSAMFILE are searched for values matching the
value read into
NAME
in the DAT record; in the second example, an alternate key at location
23 is searched for values matching the value read into
PHONE
in the DAT record.
Read a record located by its primary key value:
DATA DIVISION.
.
.
.
WORKING-STORAGE SECTION.
77 KEYLOC PIC S9(4) COMP.
.
.
.
PROCEDURE DIVISION.
START.
.
.
.
MOVE 2 TO I-O-TYPE, A-MODE.<---
prepare to open for input/output, dynamic access
CALL "CKOPEN" USING FILETABLE, STAT.
IF STATUS-KEY-1 = "9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "CKOPEN ERROR NO. ", RESULT.
IF STATUS-KEY-1 NOT="O" THEN
DISPLAY "CKOPEN FAILED"
STOP RUN.
FIND-RECORD.
READ NEW-DATA INTO DAT;<---
read update records
AT END GO TO FINISH.
MOVE 3 TO KEYLOC.
CALL "CKREADBYKEY" USING FILETABLE, STAT, REC, NAME OF DAT,
KEYLOC, RECSIZE.
IF STAT = "00" THEN
DISPLAY "RECORD FOUND", REC
GO TO FIND-RECORD.
IF STAT = "23" THEN
DISPLAY "RECORD NOT FOUND,KEY=", NAME OF DAT
GO TO FIND-RECORD.
IF STATUS-KEY-1 = "9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "ERROR NO. ", RESULT
GO TO FIND-RECORD.