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

Appendix A 193
COBOL Intrinsics
CKLOCK
lockcond
is set to 1, your process suspends until the other user unlocks the file or logs off.
The following example opens file KSAMFILE for shared access with dynamic locking
allowed. It then locks the file unconditionally. If another user has locked the file, the
process suspends until the file is unlocked and then continues by locking your file. The
status value is checked as soon as control returns to your process to ensure that the file
has been locked before continuing.
DATA DIVISION.
77 LOCKCOND PICTURE S9(4) COMP VALUE 1.
77 RESULT PICTURE 9(4) VALUE 0.
01 STATUSKEY.
02 STATUS-KEY1 PICTURE X VALUE " ".
02 STATUS-KEY2 PICTURE X VALUE " ".
01 FILETABLE.
02 FILENUMBER PICTURE S9(4) COMP VALUE 0.
02 FILENAME PICTURE X(8) VALUE "KSAMFILE".
02 I-O-TYPE PICTURE S9(4) COMP VALUE 0.
02 A-MODE PICTURE S9(4) COMP VALUE 0.
02 PREV-OP PICTURE S9(4) COMP VALUE 0.
PROCEDURE DIVISION.
START.
CALL "CKOPENSHR" USING FILETABLE, STATUSKEY.
IF STATUS-KEY1 = "0" THEN GO TO LOCK-FILE.
IF STATUS-KEY1 = "9" THEN
CALL "CKERROR" USING STATUSKEY, RESULT
DISPLAY "ERROR NO. ",RESULT.
LOCK-FILE.
CALL "CKLOCK" USING FILETABLE, STATUSKEY, LOCKCOND.
IF STATUSKEY="00"
THEN DISPLAY "CKLOCK IS OK"
ELSE IF STATUSKEY = "30"
THEN DISPLAY "FILE LOCKED BY ANOTHER PROCESS"
ELSE IF STATUS-KEY1="9"
THEN CALL "CKERROR" USING STATUSKEY, RESULT
DISPLAY "ERROR NO.", RESULT.