Microsoft KB Archive/33225

Single-Record Locking Versus Multiple-Record Locking

PSS ID Number: Q33225 Article last modified on 07-28-1988

3.00 | 3.00 MS-DOS | OS/2

Summary: This article describes the syntax in the SELECT clause that is necessary to specify single-record locking or multiple-record locking in COBOL 3.00: (The SELECT clause is part of the FILE-CONTROL paragraph in the ENVIRONMENT DIVISION.)

More Information: With the following SELECT, the file can have just one record locked at a time: SELECT … LOCK MODE … WITH LOCK ON RECORD With the following SELECT, the file can have more than one record locked at a time: SELECT … LOCK MODE … WITH LOCK ON MULTIPLE RECORDS Please note that a compilation error will be generated if the program code dealing with file or record locking conflicts with the SELECT specification. If no LOCK MODE IS MANUAL or LOCK MODE IS AUTOMATIC phrase is specified in the SELECT, the default is file-level locking. If only LOCK MODE IS AUTOMATIC is specified in the SELECT, and no WITH LOCK ON RECORD or WITH LOCK ON MULTIPLE RECORDS phrase is present, the default is single-record locking (where only one record is allowed to be locked at a time), as in the following example: 1. SELECT CUSTOMER-FILE ASSIGN “CUSTMR.DAT”. … FD CUSTOMER-FILE. 01 CUSTOMER-RECORD PIC X(80). … PROCEDURE DIVISION. OPEN I-O CUSTOMER-FILE. … This file has no multiuser syntax associated with it, so all the defaults will be taken. Assuming the OPEN is successful, after the OPEN the file will be locked for all other users attempting to access it. 2. SELECT CUSTOMER-FILE ASSIGN “CUSTMR.DAT” LOCKING MODE IS AUTOMATIC FILE STATUS IS FILE-STAT. … WORKING-STORAGE SECTION. 01 FILE-STAT PIC XX. … PROCEDURE DIVISION. OPEN I-O CUSTOMER-FILE. … READ CUSTOMER-FILE AT END … IF FILE-STAT = “9D” THEN … This file will have automatic record locking applied to it, so as the program reads a record into the program this record will be locked for other users. Since someone else may have the record locked, it is necessary to check the file status after the READ and handle the locked record appropriately. 3. SELECT CUSTOMER-FILE ASSIGN “CUSTMR.DAT” LOCK MODE IS AUTOMATIC WITH LOCK ON MULTIPLE RECORDS FILE STATUS IS FILE-STAT. … WORKING-STORAGE SECTION. 01 FILE-STAT PIC XX. … PROCEDURE DIVISION. OPEN I-O CUSTOMER-FILE. … READ CUSTOMER-FILE AT END … IF FILE-STAT = “9D” THEN … This file has automatic locking, so every READ will acquire a lock. In this case MULTIPLE record locks have been specified so locks will be accumulated each time a read is executed. Locks will continue to be accumulated until a CLOSE, COMMIT or UNLOCK statement is executed (or the program terminates). Please note that each lock requires one DOS file handle.

Copyright Microsoft Corporation 1988.