OPEN statement notes

The topic provides notes for the OPEN statement.

The notes are:

  1. 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)
  2. The successful execution of the OPEN statement places the file in open status and makes the associated record area available to the program.
  3. The OPEN statement does not obtain or release the first data record.
  4. You can move data to or from the record area only when the file is in open status.
  5. 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.
  6. The VSAMOPENFS option affects the user file status reported from successful OPEN statements on VSAM files.
  7. 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.
    For details about the CBLQDA runtime option, see CBLQDA in the z/OS® Language Environment Programming Reference.

Table 2. Permissible statements for sequential files
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.

Table 3. Permissible statements for indexed and relative files
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.

Table 4. Permissible statements for line-sequential files
Statement Input open mode Output open mode I-O open mode Extend open mode
READ X      
WRITE   X   X
REWRITE        
  1. 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.
  2. 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.
  3. If an OPEN statement is executed for a file that is already open, the EXCEPTION/ERROR procedure (if specified) for this file is run.