Compaq COBOL AAQ2G1FTK User Manual
Page 270
Sharing Files and Locking Records
8.4 Ensuring Successful Record Locking
Example 8–4 X/Open Standard Record Locking
User 1 (Automatic Record Locking):
---------------------------------
FILE-CONTROL.
SELECT FILE-1
ORGANIZATION IS RELATIVE
ASSIGN TO "SHAREDAT.DAT"
LOCK MODE AUTOMATIC.
.
.
.
PROCEDURE DIVISION.
BEGIN.
OPEN I-O FILE-1.
READ FILE-1.
.
.
.
REWRITE FILE-1-REC.
CLOSE FILE-1.
STOP RUN.
User 2 (Manual Record Locking):
------------------------------
FILE-CONTROL
SELECT FILE-1
ORGANIZATION IS RELATIVE
ASSIGN "SHAREDAT.DAT"
LOCK MODE MANUAL LOCK ON MULTIPLE RECORDS.
.
.
.
PROCEDURE DIVISION.
BEGIN.
OPEN I-O FILE-1.
.
.
.
READ FILE-1 WITH LOCK.
REWRITE FILE-1-REC.
UNLOCK FILE-1.
CLOSE FILE-1.
STOP RUN.
Note that User 2 could have employed AUTOMATIC record locking just as well.
In this case, manual and automatic locking work similarly.
8.4.2 Compaq Standard Record Locking
Automatic Record Locking (Compaq Standard)
You specify automatic record locking by using the ALLOWING phrase of the
OPEN statement. The lock is applied when you access the record and released
when you deaccess the record. In automatic record locking the access stream can
have only one record locked at a time and can apply only one type of lock to the
records of the file.
8–18 Sharing Files and Locking Records