The successful execution of an OPEN statement determines the availability
of the files and results in that file being in open mode. Table 1 summarizes
the results of opening available and unavailable files.
Table 1. Availability of a File| |
File is Available |
File is Unavailable |
| INPUT |
Normal open |
Open is unsuccessful |
| INPUT (optional file) |
Normal open |
Normal open; the first read causes the
at end condition |
| I-O |
Normal open |
Open is unsuccessful |
| I-O (optional file) |
Normal open |
Open may cause the file to be created(1) |
| OUTPUT |
Normal open; the file contains no records |
Open may cause the file to be created(1) |
| EXTEND |
Normal open |
Open is unsuccessful |
| EXTEND (optional file) |
Normal open |
Open may cause the file to be created(1) |
Note: (1) If dynamic file creation has been specified, and if the file has the
appropriate organization, the file will be created. See Dynamic File Creation.
|
- The successful execution of the OPEN statement makes the associated record
area available to the program; it does not obtain or release the first data
record.
- An OPEN statement must be successfully executed prior to the execution
of any of the permissible input-output statements, except a SORT or MERGE
statement with the USING or GIVING phrase.
- The READ statement is executed on a file which is open for INPUT or I-O.
- The WRITE statement is executed on a file which is open for OUTPUT or
EXTEND (sequential files only). The WRITE statement is also executed on an
indexed or relative file which is open for I-O in random or dynamic access
mode, and on a TRANSACTION file open for I-O.
- The REWRITE statement is executed on a file which is open for I-O.
- The START statement is executed on an indexed or relative file which is
open for INPUT or I-O.
- The DELETE statement is executed on an indexed or relative file which
is open for I-O.
- A file may be opened for INPUT, OUTPUT, I-O, or EXTEND (sequential files
only) in the same program. After the first OPEN statement execution for a
given file, each subsequent OPEN statement execution must be preceded by a
successful CLOSE file statement execution without the REEL or UNIT phrase
(for sequential files only), or the LOCK phrase.
- If the FILE STATUS clause is specified in the FILE-CONTROL entry, the
associated status key is updated when the OPEN statement is executed. For
more information about the status key, refer to Common Processing Facilities.
- If an OPEN statement is issued for a file already in the open status,
the EXCEPTION/ERROR procedure (if specified) for this file is executed and
file status 41 is returned.