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

212 AppendixA
COBOL Intrinsics
CKSTART
IF STATUS-KEY-1 = "9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "ERROR NUMBER", RESULT.
GO TO READ-BY-PHONE.
In the next example, CKSTART is used to position to the beginning of the series of names
beginning with the letter "T". The KSAM file key is located at character position 3 (
NAME
key); the parameter
KEYVAL
is set to the value "T"; the key length for purposes of
comparison is set to 1; and
RELOP
is set to 0. Thus the record pointer is positioned at the
first key found whose value (when the key is truncated to 1 character) is equal to "T". Note
that this example reads not only all names beginning with "T", but also reads all names
that begin with letters following "T". To read only the names beginning with "T", the
program must add a test for the end of the "T" names.
POSITION.
MOVE 0 TO RELOP.<---
find key equal to KEY value
MOVE "T" TO KEYVAL.
MOVE 3 TO KEYLOC.
MOVE 1 TO KEYLENGTH.
CALL "CKSTART" USING FILETABLE, STAT, RELOP, KEYVAL, KEYLOC,
KEYLENGTH.
IF STAT = "23" THEN GO TO FINISH.
IF STATUS-KEY-1 = "0" THEN
GO TO READ-NAMES.
DISPLAY "CKSTART ERROR, STATUS=",STAT.
IF STATUS-KEY-1 = "9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "ERROR NUMBER=", RESULT.
GO TO FINISH.
READ-NAMES.
CALL "CKREAD" USING FILETABLE, STAT, REC, RECSlZE.
IF STATUS-KEY-1 ="1" THEN GO TO FINISH.
IF STATUS-KEY-1 ="0" THEN
DISPLAY REC;
ELSE
DISPLAY "CKREAD ERROR, STATUS",STAT.
IF STATUS-KEY-1 = "9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "ERROR NUM", RESULT.
GO TO READ-NAMES.