Compaq COBOL AAQ2G1FTK User Manual
Page 273
Sharing Files and Locking Records
8.4 Ensuring Successful Record Locking
Table 8–5 (Cont.) Manual Record Locking Combinations
Lock Held (for first stream)
I-O Attempt (for
subsequent stream)
Updaters
Readers
No Others
Allowing Readers
Y
Y
N
Allowing no others
Y
Y
N
WRITE
Allowing no others
N/A
N/A
N/A
Legend: Y = Subsequent stream executes successful I-O operation
N = Subsequent stream I-O operation is unsuccessful (File Status 92)
Example 8–6 uses manual record locking. The file is opened with the ALLOWING
ALL clause. The records are read but do not become available to other access
streams because of the lock applied by the READ statement (READ...ALLOWING
NO OTHERS). When the UNLOCK is executed, the records can be read by
another access stream if that stream opens the file allowing writers.
Example 8–6 Sample Program Using Manual Record Locking (Compaq
Standard)
FILE-CONTROL.
SELECT FILE-1
ORGANIZATION IS RELATIVE
ASSIGN "SHAREDAT.DAT".
.
.
.
I-O-CONTROL.
APPLY LOCK-HOLDING ON FILE-1.
.
.
.
PROCEDURE DIVISION.
BEGIN.
OPEN I-O FILE-1 ALLOWING ALL.
.
.
.
READ FILE-1 ALLOWING NO OTHERS AT END DISPLAY "end".
.
.
.
REWRITE FILE-1-REC ALLOWING NO OTHERS.
.
.
.
UNLOCK FILE-1 ALL RECORDS.
CLOSE FILE-1.
STOP RUN.
In manual record locking, you release record locks by the UNLOCK statement or
when you close the file (either explicitly or implicitly; when you close a file, any
existing record lock is released automatically). The UNLOCK statement provides
for either releasing the lock on the current record (on OpenVMS Alpha systems
with UNLOCK RECORD) or releasing all locks currently held by the access
Sharing Files and Locking Records 8–21