Sharing Files and Locking Records
8.3 Ensuring Successful File Sharing
8.3.3 Determining the Intended Access Mode to a File
Once you establish disk residency and permission for a file, you can consider
how the stream intends to access the file. You specify this intention by using the
Compaq COBOL open and access modes.
The Compaq COBOL open modes are INPUT, OUTPUT, EXTEND, and I-O. The
Compaq COBOL access modes are SEQUENTIAL, RANDOM, and DYNAMIC.
The combination of open and access modes determines the operations intended on
the file.
You must validate your Compaq COBOL intention against the file protection
assigned by the file owner. For example, to use an OPEN INPUT clause requires
that the file owner has granted read access privileges to the file. To use an OPEN
OUTPUT or EXTEND clause requires write access privileges to the file. To use
an OPEN I-O clause requires both read and write access privileges.
The following chart shows the relationship between open and access modes and
intended Compaq COBOL operations. The word ANY indicates that all three
access methods result in the same intentions.
Open Mode Access Mode Intended COBOL Operations
INPUT ANY READ, START
OUTPUT ANY WRITE
I-O SEQUENTIAL READ, START, REWRITE, DELETE
RANDOM/DYNAMIC READ, START, REWRITE, DELETE, WRITE
EXTEND SEQUENTIAL WRITE
Note
If the file protection does not permit the intended operations, file access is
not granted, even if open and access modes are compatible.
File protection and open mode access apply to both the unshared and shared
(multiple access stream) file environments. A file protection and intent check is
made when the first access stream opens a file (in the unshared file environment),
and again when the second and subsequent access streams open the file (in the
shared file environment).
After you provide disk residency, specify permission, and determine the access
mode to a file, you can specify the access allowed to other streams through file-
sharing and record-locking techniques. The remainder of this chapter describes
this access control.
8.3.4 Specifying File Access Using X/Open Standard File Sharing
X/Open standard file sharing is summarized in this section and fully described
in the Compaq COBOL Reference Manual (Environment Division and Procedure
Division chapters) and the X/Open CAE Specification: COBOL Language.
If you want a file in your COBOL program to utilize X/Open standard file sharing
(probably for purposes of portability), you should include X/Open-specific syntax
for the file in the Environment Division. Use one of the following:
LOCK MODE IS AUTOMATIC
LOCK MODE IS MANUAL
8–6 Sharing Files and Locking Records