COBOL Manual for TNS/E Programs (H06.03+)

Procedure Division Verbs
HP COBOL Manual for TNS/E Programs520347-003
9-140
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.
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.
Table 9-9. Open Modes for Structured Disk Files Present at Run
Time (page 1 of 2)
Open Mode Action
INPUT If the record length of the physical file is shorter than the record length
declared in the File Section, and the record length is not declared as
variable (rec-1 TO rec-2 CHARACTERS or VARYING SIZE), the OPEN
statement fails.
If the open operation succeeds and the file organization is relative, the
relative key is established as the key of reference.
If the open operation succeeds and the file organization is indexed, the
prime record key is established as the key of reference.
The file position indicator is set so that the first execution of a READ
statement retrieves either of these, depending on the file’s organization:
The first record in a sequential file
The first record in the sequence defined by the key of reference in an
indexed, queue, or relative file