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

188 AppendixA
COBOL Intrinsics
CKDELETE
Following the call to CKDELETE, the pointer is positioned to the next key following the key
in the deleted record.
The following examples show the use of CKDELETE for sequential access using CKREAD and
for random access using CKREADBYKEY. The WORKING-STORAGE SECTION from Figure
A-2. and the FINISH procedure from the CKCLOSE example are assumed for these
examples.
NOTE
If access is shared, the file must be opened with a call to CKOPENSHR and then
locked before the call to CKSTART that initially sets the pointer. The file must
remain locked while the records to be deleted are read and then marked for
deletion. If the file is not locked before CKSTART is called, other users can
change the file so that the record pointer points to the wrong record.
In the first example, to delete all records whose primary key begins with "P", first position
the file to the start of these records with CKSTART and then read each record with CKREAD
and delete it with CKDELETE.
WORKING-STORAGE SECTION.
77 RELOP PIC S9(4) COMP.
77 KEYVAL PIC X(20).
77 KEYLOC PIC S9(4) COMP.
77 KEYLENGTH PIC S9(4) COMP.
.
.
.
PROCEDURE DIVISION.
START.
MOVE 2 TO I-O-TYPE.
MOVE 0 TO A-MODE.
CALL "CKOPEN" USING FILETABLE, STAT.
.
.
.
FIND-REC.
MOVE 0 TO RELOP.<---
test for equality between
primary key and KEY
MOVE "P" TO KEYVAL.
MOVE 3 TO KEYLOC.
MOVE 1 TO KEYLENGTH.<---
check first character only
CALL "CKSTART" USING FILETABLE, STAT, RELOP, KEYVAL, KEYLOC,
KEYLENGTH.
IF STATUS-KEY-1 = "0" THEN
GO TO READ-REC.
IF STAT = "23" THEN
DISPLAY "NO RECORD FOUND"
GO TO FINISH.
IF STATUS-KEY-1 = "9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "CKERROR NO.=", RESULT
GO TO FINISH.