COBOL Manual for TNS and TNS/R Programs

Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs522555-006
9-152
OPEN
Structured Disk Files Present at Run Time
Certain requirements pertain to all files in this category:
°
The organization declared for the file must be consistent with the actual
organization of the file (that is, if the file is declared ORGANIZATION
SEQUENTIAL, the file must be entry-sequenced; if it is declared
ORGANIZATION RELATIVE, the file must be relative; and if it is declared
ORGANIZATION INDEXED, the file must be key-sequenced).
°
If the file is key sequenced or has alternate keys, the declaration of the keys in
the COBOL program must agree with the declaration of the keys in the file
system.
°
The file security must be appropriate for the open mode. You cannot open a file
for INPUT or I-O if it is secured against your reading it. You cannot open a file
for OUTPUT, I-O, or EXTEND if it is secured against your writing to it.
When the preceding requirements are met for a disk file present at run time, the
open mode determines what happens during execution.
Table 9-8. Open Modes for Structured Disk Files Not Present at Run Time
Open Mode Action
INPUT When the SELECT clause for the file contains the word OPTIONAL, the
OPEN statement completes successfully, and COBOL simulates the
existence of an empty disk file. If the file is not described as OPTIONAL, the
open operation fails.
OUTPUT or
EXTEND or
I-O
If a file is described with alternate-record keys, the open operation fails. A
COBOL program cannot create files with alternate keys. When the disk file
is otherwise described, COBOL creates the file (see Structured Disk Files
Present at Run Time).
If the device name is associated with a proper file name (such as
$volumename.subvolname.filename), then the created file is permanent and
continues to exist after the program has closed it. If the device name is not
associated with a proper file name (that is, if its name has the form of just a
volume name or is a special name like #TEMP), the created file is temporary
and disappears when it is closed.
The device name can be associated with a proper file name in any of these
ways:
By the ASSIGN clause at compile time
By an ASSIGN command at run time
By a DEFINE of class MAP at run time
Caution. If you open a disk file for shared access, do not use sequential block buffering,
because one process can read data from the file that is not up-to-date while another process is
altering the file. See the explanation of the RESERVE clause in file-control entries under FILE-
CONTROL Paragraph.