Sharing Files on Multi-user Systems

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:

The organization of the file affects the way the file can be shared:

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.

Single Record Locking

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 lock is released by the same run unit doing any of the following:

Multiple Record Locking

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 locks are released by the same run unit doing any of the following:

Default Record Locking

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.)

XOPENX/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.

OPEN Mode No Directive AUTOLOCK Compiler Directive Override in SELECT Statement
INPUT No lock No lock Yes, but only to Exclusive
I-O Exclusive Lock on single record Yes
OUTPUT Exclusive Exclusive No
EXTEND Exclusive No lock Yes, the file can be made shareable but no records are locked
Table 1: Default Locking For Record Sequential Files
OPEN Mode No Directive AUTOLOCK Compiler Directive Override in SELECT Statement
INPUT No lock No lock No
I-O Exclusive No lock No
OUTPUT Exclusive Exclusive No
EXTEND Exclusive No lock No
Table 2: Default Locking For Line Sequential Files
OPEN Mode No Directive AUTOLOCK Compiler Directive Override in SELECT Statement
INPUT No lock No lock Yes, but only to Exclusive
I-O Exclusive Automatic lock on single record Yes
OUTPUT Exclusive Exclusive No
EXTEND Exclusive Exclusive No
Table 3: Default Locking For Relative And Indexed Files

Notes:

  1. A file opened for OUTPUT causes the file to become exclusive, regardless of the specified lock mode.
  2. You can select the type of locking for individual files by accepting the default locking (see Tables 1, 2 and 3) or by including a LOCK MODE clause in the file control entry (see the section The File Control Entry).