The topic provides notes for the OPEN statement.
The notes are:
- The successful execution of an OPEN statement determines the availability
of the file and results in that file being in open mode.
A file is available if it
is physically present and recognized by the input-output control system.
The following table shows the results of opening available and unavailable
files.
Table 1. Availability
of a fileOpened as |
File is available |
File is unavailable |
INPUT |
Normal open |
Open is unsuccessful. (file status 35) |
INPUT (optional file) |
Normal open |
Normal open; the first read causes the at end
condition or the invalid key condition. (file status 05) |
I-O |
Normal open |
Open is unsuccessful. (file status 35) |
I-O (optional file) |
Normal open |
Open causes the file to be created. (file status
05) |
OUTPUT |
Normal open; the file contains no records |
Open causes the file to be created. |
EXTEND |
Normal open |
Open is unsuccessful. (file status 35) |
EXTEND (optional file) |
Normal open |
Open causes the file to be created. (file status
05) |
- The successful execution of the OPEN statement places the file
in open status and makes the associated record area available to the
program.
- The OPEN statement does not obtain or release the first data record.
- You can move data to or from the record area only when the file
is in open status.
- 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. In the following
table, an 'X' indicates that the specified statement can be used with
the open mode given at the top of the column.
Table 2. Permissible
statements for sequential filesStatement |
Input open mode |
Output open mode |
I-O open mode |
Extend open mode |
READ |
X |
|
X |
|
WRITE |
|
X |
|
X |
REWRITE |
|
|
X |
|
In the following table, an 'X' indicates that the specified
statement, used in the access mode given for that row, can be used
with the open mode given at the top of the column.
Table 3. Permissible
statements for indexed and relative filesFile access mode |
Statement |
Input open mode |
Output open mode |
I-O open mode |
Extend open mode |
Sequential |
READ |
X |
|
X |
|
WRITE |
|
X |
|
X |
REWRITE |
|
|
X |
|
START |
X |
|
X |
|
DELETE |
|
|
X |
|
Random |
READ |
X |
|
X |
|
WRITE |
|
X |
X |
|
REWRITE |
|
|
X |
|
START |
|
|
|
|
DELETE |
|
|
X |
|
Dynamic |
READ |
X |
|
X |
|
WRITE |
|
X |
X |
|
REWRITE |
|
|
X |
|
START |
X |
|
X |
|
DELETE |
|
|
X |
|
In the following table, an 'X' indicates that the specified
statement can be used with the open mode given at the top of the column.
Table 4. Permissible
statements for line-sequential filesStatement |
Input open mode |
Output open mode |
I-O open mode |
Extend open mode |
READ |
X |
|
|
|
WRITE |
|
X |
|
X |
REWRITE |
|
|
|
|
- A file can be opened for INPUT, OUTPUT, I-O, or EXTEND (sequential
and line-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
LOCK phrase.
- If the FILE STATUS clause is specified in the file-control entry,
the associated file status key is updated when the OPEN statement
is executed.
- If an OPEN statement is executed for a file that is already open,
the EXCEPTION/ERROR procedure (if specified) for this file is run.