Microsoft KB Archive/33222

Explanation of Network File-Level and Record-Level Locking

PSS ID Number: Q33222 Article last modified on 11-08-1991

3.00 3.00a 4.00 4.50 | 3.00 3.00a 4.00 4.50 MS-DOS | OS/2

Summary: There are two types of locking that can be invoked in a Microsoft COBOL Version 3.00, 3.00a, 4.00, or 4.50 program running in a network environment: file-level locking and record-level locking. The characteristics of the two types of locking are described later in this article. The LOCK MODE is specified in the SELECT clause of the FILE-CONTROL paragraph in the ENVIRONMENT DIVISION. There is also an ANSI ’85 COBOL extension to specify an OPEN … WITH LOCK statement to execute file-level locking in the PROCEDURE DIVISION.

More Information: The following are types of locking: 1. File-Level Locking a. Under file-level locking, if one workstation has a file OPEN, another station cannot OPEN the same file. b. File-level locking is available for all file types. c. File-level locking is also called LOCK MODE IS EXCLUSIVE. d. You can optionally specify file-level locking with the LOCK MODE IS phrase in the SELECT clause, for example: SELECT file-name ASSIGN TO DISK LOCK MODE IS EXCLUSIVE. e. When you use the no LOCK MODE IS phrase in the SELECT clause, the locking mode defaults to file-level locking. f. File-level locks are detected in file status bytes as “9A” or by run-time error 9/065. 2. Record-Level Locking a. Under record-level locking, if one workstation OPENs a file and READs records in a file, then another station can OPEN the same file and READ and modify records other than those “locked” by the first workstation. b. Multiple different workstations may have one or more records locked per file. c. Files opened as LINE SEQUENTIAL do not support record-level locking. d. Record-level locking is only available for files opened with the OPEN I-O or OPEN EXTEND statements. Record-level locking is not available for files opened with the OPEN INPUT or OPEN OUTPUT statements. e. You must explicitly specify record-level locking with the LOCK MODE IS AUTOMATIC or LOCK MODE IS MANUAL phrase in the SELECT clause, as in the following example: SELECT file-name-1 ASSIGN TO DISK LOCK MODE IS AUTOMATIC. SELECT file-name-2 ASSIGN TO DISK LOCK MODE IS MANUAL. f. Only files on network (shared) drives can have record locks applied to them. g. Record locks are detected in file status bytes as “9D” or by run-time error 9/068.

Copyright Microsoft Corporation 1991.