ISO2002MF 

Sharing Mode

The sharing mode indicates whether a file is to participate in file sharing and record locking, and specifies the degree of file sharing (or non-sharing) to be permitted for the file. The sharing mode specifies the types of operations that may be performed on the shared file through other file connectors while this file connector is open.

The SHARING phrase on an OPEN statement overrides the SHARING clause in the file control entry for establishing the sharing mode. If there is no SHARING phrase on the OPEN statement, the sharing mode is completely determined by the SHARING clause in the file control entry. If no specification is made in either location, the sharing mode is determined by the first of the following conditions that is satisfied:

The rules are the same for a given standard sharing mode whether the sharing mode is specified on the OPEN statement, specified in the file control entry, or determined from the list above.

COBOL file sharing does not interoperate with other file sharing facilities in the environment.

A shared file must reside on disk.

Before access to a shared file is allowed through an OPEN statement, the sharing mode and the open mode must be allowed by all other file connectors that are currently associated with the file. Additionally, the sharing mode for the current OPEN statement shall permit all of the sharing modes and open modes that exist for all other file connectors that are currently associated with the file. (See the topic The OPEN Statement, particularly the table Opening available shared files that are currently open by another file connector.)

The sharing mode controls access to a file as follows:

  1. The SHARING WITH NO OTHER mode specifies exclusive access to a file. Associating this file connector with the file will be unsuccessful if the file is currently open through other file connectors. If the OPEN statement is successful, subsequent requests to open the file through other file connectors before this file connector is closed will be unsuccessful. Record locks are ignored.
  2. The SHARING WITH READ ONLY mode restricts concurrent access to a file through file connectors other than this one, to input mode. Associating this file connector with the file will be unsuccessful if the file is currently open in a mode other than input. If the OPEN statement is successful, subsequent requests to open the file through other file connectors in a mode other than input before this file connector is closed will be unsuccessful. Record locks are in effect.
  3. The SHARING WITH ALL OTHER mode allows concurrent access to a file through other file connectors specifying input, I-O, or extend mode, subject to any further restrictions that apply. Record locks are in effect.

Multiple paths of access may exist in the same run-time element, contained elements, separate run-time modules within the same run unit, or different run units. The file sharing conflict condition can exist regardless of the location of the file connector that holds the file lock of the file to be opened.

The setting of a file lock is part of the atomic operation of an I/O statement.

The file lock and all record locks established for a file connector are removed by an explicit or implicit CLOSE statement executed for that file connector.