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

190 AppendixA
COBOL Intrinsics
CKDELETE
In the second example, a file containing the primary keys of those records to be deleted
from a KSAM file is read into the working storage area DAT. These key values are used by
CKREADBYKEY to locate and read the items to be deleted by CKDELETE.
PROCEDURE DIVISION.
START.
MOVE 2 TO I-O-TYPE, A-MODE.
CALL "CKOPEN" USING FILETABLE, STAT.
.
.
.
READ-KEY.
READ DATA-FILE INTO DAT;
AT END GO TO FINISH.
CALL "CKREADBYKEY" USING FILETABLE, STAT, REC, NAME OF DAT, KEYLOC,
RECSIZE.
IF STATUS-KEY-1 = "0" THEN
GO TO DELETE-RECORD.
DISPLAY "CKREADBYKEY ERROR, STATUS = ",STAT.
IF STATUS-KEY-1 = "9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "CKERROR ", RESULT
GO TO READ-KEY.
DELETE-RECORD.
CALL "CKDELETE" USING FILETABLE, STAT.
IF STATUS-KEY-1 = "0" THEN
DISPLAY REC, " DELETED"
GO TO READ-KEY.
DISPLAY "CKDELETE ERROR, STATUS =",STAT.
IF STATUS-KEY-1 = "9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "CKERROR NO. =", RESULT.
GO TO READ-KEY.
NOTE
If access is shared, the file must be opened with a call to CKOPENSHR. A call to
CKLOCK must precede the call to CKREADBYKEY. A call to CKUNLOCK must follow
the CKDELETE error tests and should precede the return to READ-KEY.