The run-time system supports this COBOL system's multi-user facilities which allow files to be shared between users in a multi-user environment, and allow runtime elements accessing those files to lock records or entire files in order to prevent access to them while data is being updated.
In single-user environments the multi-user syntax has no effect at run time, but runtime elements can be developed for use in both single- and multi-user environments.
Files are either active or inactive. An active file is open to one or more run units. An inactive file is one that is not open to any run unit.
Active files can be open in one of two modes: exclusive or shareable:
A file which is in exclusive mode is open to one run unit only; any other run unit which attempts to access it receives a "File locked" error and is denied access. Exclusive mode implies that a file lock is held by the one run unit which is able to access the file; the file lock is released by that run unit closing the file.
A file which is in shareable mode is available to any number of run units, each of which can protect data while using the file by locking one or more records at a time in the file. This prevents other run units from acquiring a lock on the individual records that are locked, but does not prevent access to the file otherwise. The organization of the file affects the way the file can be shared.
The organization of the file affects the way the file can be shared:
Record sequential files opened for INPUT can be shared between run units but records cannot be locked in the file. Files opened for I-O or EXTEND can also be made shareable and each run unit can maintain a record lock for the file. Files opened for OUTPUT always have an exclusive file lock.
Line sequential files that are opened INPUT or EXTEND can be made shareable but records cannot be locked in the file. Files that are opened OUTPUT always have an exclusive file lock.
Files that are opened in INPUT mode are shareable, but records cannot be locked in the file. Files that are opened I-O can be shareable but files that are opened OUTPUT or EXTEND are exclusive.
Each run unit that is sharing access to a file can be locking either a single record or multiple records in that file. A run unit cannot select single record locking and multiple record locking for the same file.
A run unit that has specified single record locking for a file (either explicitly or implicitly) can hold only one record lock in that file at any one time. A run unit can acquire a record lock in two ways: manually or automatically:
The run unit acquires a lock only if it accesses a record with a READ WITH LOCK statement.
The run unit acquires a lock whenever it reads a record in the file, unless you specify the READ WITH NO LOCK statement.
The lock is released by the same run unit doing any of the following:
Locking of multiple records in a file is available only when the organization of that file is relative, indexed or record sequential.
A run unit that has specified multiple record locking for a file can hold a number of record locks in one file simultaneously. This prevents other run units from updating or acquiring a lock on those locked records, but does not deny them access to any records that are not locked. Record locks can be acquired in two ways: manually or automatically:
The run unit acquires a lock only if it accesses a record with a READ WITH LOCK or READ WITH KEPT LOCK statement.
The run unit acquires a lock whenever it reads a record in the file unless you explicitly specify that it should not. If the WRITELOCK Compiler directive has been specified at the time the compilation group was submitted to your COBOL system, then a lock is acquired if the run unit accesses the file with a WRITE or REWRITE statement.
The locks are released by the same run unit doing any of the following:
Tables 2, 3 and 4 show the default type of locking which is used when files are opened in a particular open mode. The default locking can be modified if the AUTOLOCK Compiler directive was specified at the time the compilation group was submitted to your COBOL system. The tables also indicate whether the default type of locking can be overridden for individual files. This is done by inserting a suitable clause in the SELECT clause for the file. (See the topic The File Control Entry.)
X/Open restricts those X/Open conforming source programs that use locking
to either single record locks with automatic locking, or multiple record locks
with manual locking.
Notes: