OPEN statement notes
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 QSAM file is available if it
has a DD allocation and is physically present. A VSAM file is available if
it has a DD allocation, has been defined using VSAM access method
services, and contains records or has previously contained records.
For more information regarding file availability, see
Opening
a file (ESDS, KSDS, or RRDS) in
the Enterprise COBOL Programming Guide.
The following table shows the results of opening available and unavailable
files.
Table 1. Availability of a file Opened 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.
- The VSAMOPENFS option affects the user file status reported from successful OPEN statements on VSAM files.
- The
CBLQDA Language Environment® (LE) runtime option affects the user file status
reported from OPEN statements on QSAM files that are not found:
- With CBLQDA(ON), LE would create a temporary data set and the OPEN would be successful.
- With CBLQDA(OFF), LE would not create a temporary data set and the OPEN would fail.
Statement | 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.
File 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.
Statement | 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 REEL or UNIT phrase (for QSAM files only), or 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.