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

200 AppendixA
COBOL Intrinsics
CKREAD
can be made incorrect by other users without your program being aware of it. For this
reason, you should lock the file, position the pointer with a pointer-independent procedure,
and then call CKREAD. When the last record is read, you should then unlock the file so other
users can access the file. Example 2 below illustrates how you should read the file
sequentially when access is shared.
Using the WORKING-STORAGE SECTION from Figure A-2. and the FINISH procedure
in the CKCLOSE example, the following procedures read records in sequential order from file
KSAMFILE and display them on the standard output device.
PROCEDURE DIVISION.
START.
.
.
.
MOVE 0 TO I-O-TYPE, A-MODE.
CALL "CKOPEN" USING FILETABLE, STAT.
IF STATUS-KEY-1 = "9"
CALL "CKERROR" USING STAT, RESULT
DISPLAY "CKOPEN ERROR NO. ", RESULT.
IF STATUS-KEY-1 NOT = "0"
DISPLAY "CKOPEN FAILED"
STOP RUN.
READ-NEXT.
CALL "CKREAD" USING FILETABLE, STAT, REC, RECSIZE.
IF STATUS-KEY-1 = "1" GO TO NEW-POSITION.
IF STATUS-KEY-1 = "0"
DISPLAY REC;
ELSE
DISPLAY "CKREAD ERROR, STATUS =", STAT.
IF STATUS-KEY-1 ="9"
CALL "CKERROR" USING STAT, RESULT
DISPLAY "FILE ERROR =", RESULT.
GO TO READ-NEXT.
NEW-POSITION.
.
.
.