Using KSAM/XL and KSAM 64 (32650-90886)
Appendix A 197
COBOL Intrinsics
CKOPEN
WORKING-STORAGE SECTION.
77 RESULT PIC 9(4) VALUE ZERO.
01 FILETABLE.
03 FILENUMBER PIC S9(4) COMP VALUE ZERO.
03 FILENAME PIC X(8) VALUE "KSAMFILE".
03 I-O-TYPE PIC S9(4) COMP VALUE ZERO.<---
input only
03 A-MODE PIC S9(4) COMP VALUE ZERO.<-----
sequential access
03 PREV-OP PIC S9(4) COMP VALUE ZERO.
01 STAT.
03 STATUS-KEY-1 PIC X.
03 STATUS-KEY-2 PIC X.
.
.
.
PROCEDURE DIVISION.
START.
CALL "CKOPEN" USING FILETABLE, STAT.
IF STATUS-KEY-1 ="0" THEN GO TO S-READ.
IF STATUS-KEY-1 ="9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "CKOPEN FAILED. . .ERROR NO.", RESULT
STOP RUN.
S-READ.
.
.
.
If you subsequently want to write in sequential order to the same file, you should close the
file with a call to CKCLOSE (described below), move the value 1 (output to I-O-TYPE and
then reopen the file:
CALL "CKCLOSE" USING FILETABLE, STAT.
IF STATUS-KEY-1 ="9" THEN
CALL "CKERROR" USING STAT, RESULT
DISPLAY "CKCLOSE FAILED -- ERROR NO.",
STOP RUN.
MOVE 1 TO I-O-TYPE.<---
output only
CALL "CKOPEN" USlNG FILETABLE, STAT.
Similarly, to update records in random order in the same file, first close the file, then use
the following MOVE statement to alter the input/output type and access mode in FILETABLE
and reopen the file:
CALL "CKCLOSE" USING FILETABLE, STAT.
.
.
.
MOVE 2 TO I-O-TYPE.<---
input/output
MOVE 1 TO A-MODE.<---
random access
CALL "CKOPEN" USING FILETABLE, STAT.