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

Appendix B 239
BASIC/V Intrinsics
BKLOCK
Users who share the same file should cooperate on how they will share the file. Unless they
all agree to allow locking, no one will be able to lock the file. Also, it is important to avoid
situations where one user locks the file and forgets to unlock it. If this occurs when
condition
is set to a non-zero value, the calling process is not halted. But if the file is
locked already and you attempt to lock a file with
condition
omitted or set to zero, your
process is halted until the other user either unlocks the file or logs off.
You should always check the
status
parameter immediately following a call to BKLOCK in
order to determine if the call was completed successfully. If you locked with
condition
set
to a nonzero value, you should check if the file was locked before continuing. If it was
locked, status will have a 0 in the first character, but if another user had locked the file
preventing your call to BKLOCK from working, then status contains the value 71.
Figure B-3. contains an example of locking a file with BKLOCK.
Figure B-3. Dynamically Locking a KSAM File with BKLOCK
830 REM ********************************************************
840 REM * LOCK A KSAM FILE *
850 REM ********************************************************
855 REM
860 REM F IS THE FILE NUMBER OF A KSAM FILE
870 REM OPENED BY A CALL TO BKOPEN
890 REM
900 REM THE THIRD PARAMETER INDICATES THAT LOCKING IS
910 REM TO TAKE PLACE UNCONDITIONALLY
920 REM
930 CALL BKLOCK(F,S$,0)
940 REM
950 REM NOW DETERMINE WHETHER THIS CALL HAS SUCCEEDED
960 REM
970 IF S$[1;1]<>"0" THEN DO
980 REM N$ CONTAINS THE NAME OF THE KSAM FILE
990 REM S$ CONTAINS THE STATUS CODE SET BY THE PRECEDING CALL
1000 PRINT "UNABLE TO LOCK ";$N;" ERROR ";N$;" "LS$[1;1];" DETAIL ";S$[2]
1010 CALL BKERROR(S$,M$)
1020 PRINT M$
1030 DOEND