The OPEN Statement

The OPEN statement initiates the processing of files. It also performs checking and/or writing of labels and other input-output operations.

ANS85 The REVERSED phrase of the OPEN statement is classed as an obsolete element in the ANSI'85 standard and is scheduled to be deleted from the next full revision of the ANSI Standard.

MF All dialects in this COBOL implementation fully support this syntax. The FLAGSTD Compiler directive can be used to detect all occurrences of this syntax.

XOPEN Although it is a part of the standard COBOL definition, the REVERSED phrase of the OPEN statement is explicitly excluded from the X/Open COBOL language definitions and should not be used in a conforming X/Open COBOL source program.

MF The OPEN statement allocates system resources for a synchronization data item and initializes the data item.

General Formats for Format 1 (Record Sequential Files)


*

General Formats for Format 2 ( MF Line Sequential, Relative and Indexed Files)


*
MF 

General Formats for Format 3 (Synchronization Data Items)


*

Syntax Rules for All Formats (All Files)

  1. The files referenced in the OPEN statement need not all have the same organization or access.
  2. ISO2002MF If SHARING ALL is specified and the INPUT phrase is not specified, the LOCK MODE clause must be specified in the file control entry for file-name-1.

Syntax Rules for Format 1 (Record Sequential Files)

  1. MF NO REWIND is documentary only.
  2. The I-O phrase can be used only for disk files.
  3. The EXTEND phrase must be used only for files for which the LINAGE clause has not been specified.
  4. The EXTEND phrase must not be specified with multiple file reels.
  5. The REVERSED phrase can be used only for fixed-length record sequential files.

Syntax Rules for Format 2 (MF Line Sequential, Relative and Indexed Files)

  1. ANS85 The EXTEND phrase can be used for files in sequential access mode.
  2. ISO2002MF The SHARING phrase must not be specified for files with line sequential organization.
MF 

Syntax Rules for Format 3 (Synchronization Data Items)

  1. MF Identifier-1 must reference an elementary data item with a USAGE of EVENT-POINTER, MONITOR-POINTER, MUTEX-POINTER or SEMAPHORE-POINTER.

General Rules for Formats 1 and 2 (All Files)

  1. Prior to the successful execution of an OPEN statement for a given file, no statement (except for a SORT or MERGE statement with the USING or GIVING phrases) can be executed that references that file, either explicitly or implicitly.
  2. ISO2002MF The successful execution of an OPEN statement determines the availability of the file and results in the file connector referenced by the file-name being in an open mode. The successful execution of an OPEN statement associates the file with the file-name through a file connector.

    The key words INPUT, OUTPUT, I-O, and EXTEND specify the type of input-output operations intended for the file through the file connector and establish the open mode. (See table 14-4, Permissible Combinations of Statements and OPEN Modes.)

    A file is available if it is physically present and is recognized by the file handling system. Table 1, Opening Available and Unavailable Files (file not currently open), shows the results of opening available and unavailable files that are not currently open. Table 2, Opening Available Shared Files that are Currently Open by Another File Connector, shows the results of opening available and unavailable files that are currently open by another file connector.

    Table 1. Opening Available and UnavailableFiles (File not Currently Open)
    Open Mode 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 or invalid key condition
    I-O Normal open Open is unsuccessful
    I-O (optional file) Normal open Open causes the file to be created
    OUTPUT Normal open; the file contains no records Open causes the file to be created
    EXTEND Normal open Open is unsuccessful
    EXTEND (optional file) Normal open Open causes the file to be created
    Table 2. Opening Available SharedFiles that are Currently Open by Another File Connector
    Open request Most Restrictive Existing Sharing Mode and Open Mode
    Sharing with no Other Sharing with Read Only Sharing with All Other
    extend/ I-O/ input/ output extend/ I-O/ output input extend/ I-O/ output input
    SHARING WITH NO OTHER EXTEND/ I-O/ INPUT/ OUTPUT/ Unsuccessful open Unsuccessful open Unsuccessful open Unsuccessful open Unsuccessful open
    SHARING WITH READ ONLY EXTEND/ I-O Unsuccessful open Unsuccessful open Unsuccessful open Unsuccessful open Normal open
    INPUT Unsuccessful open Unsuccessful open Normal open Unsuccessful open Normal open
    OUTPUT Unsuccessful open Unsuccessful open Unsuccessful open Unsuccessful open Unsuccessful open
    SHARING WITH ALL OTHER EXTEND/ I-O Unsuccessful open Unsuccessful open Unsuccessful open Normal open Normal open
    INPUT Unsuccessful open Normal open