ILE COBOL Language Reference

OPEN Statement Programming Notes

The successful execution of an OPEN statement determines the availability of the files and results in that file being in open mode. Table 31 summarizes the results of opening available and unavailable files.

Table 31. 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.
  1. 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.
  2. 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.
  3. The READ statement is executed on a file which is open for INPUT or I-O.
  4. 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.
  5. The REWRITE statement is executed on a file which is open for I-O.
  6. The START statement is executed on an indexed or relative file which is open for INPUT or I-O.
  7. The DELETE statement is executed on an indexed or relative file which is open for I-O.
  8. 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.
  9. 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.
  10. 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.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]