beautypg.com

Compaq COBOL AAQ2G1FTK User Manual

Page 254

background image

Sharing Files and Locking Records
8.1 Controlling Access to Files and Records

File sharing and record locking allow you to control file and record operations
when more than one access stream (the series of file and record operations
being performed by a single user, using a single file connector) is concurrently
accessing a file, as in Figure 8–1.

A Compaq COBOL program, via the I/O system, can define one or more access
streams. You create one access stream with each OPEN file-name statement. The
access stream remains active until you terminate it with the CLOSE file-name
statement or until your program terminates.

File sharing allows multiple users (or access streams) to access a single file
concurrently. The protection level of the file, set by the file owner, determines
which users can share a file.

Record locking controls simultaneous record operations in files that are
accessed concurrently. Record locking ensures that when a program is writing,
deleting, or rewriting a record in a given access stream, another access stream is
allowed to access the same record in a specified manner.

Figure 8–2 illustrates the relationship of record locking to file sharing.

Figure 8–2 Relationship of Record Locking to File Sharing

Manual

Record Locking

FILE SHARING

Automatic

Record Locking

ZK−6105−GE

File sharing is a function of the file system, while record locking is a function
of the I/O system. The file system manages file placement and the file-sharing
process, in which multiple access streams simultaneously access a file. The
I/O system manages the record-sharing process and provides access methods to
records within a file. This includes managing the record-locking process, in which
multiple access streams simultaneously access a record.

You must have successful file sharing before you can consider record locking.

In Compaq COBOL, the file operations begin with an OPEN statement and end
with a CLOSE statement. The OPEN statement initializes an access stream and
specifies the mode. The CLOSE statement terminates an access stream and can
be either explicit (stated in the program) or implicit (on program termination).

Note

The first access stream to open a file determines how other access streams
can access the file concurrently (if at all).

The record operations for Compaq COBOL that are associated with record locking
are as follows:

READ
START

8–2 Sharing Files and Locking Records