Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

OPEN statement

Function

The OPEN statement opens files for processing and performs label checking and output for sequentially organized files.

Format 1 for sequential file organization


OPEN {  INPUT {file-name-1 [ REVERSED | WITH NO REWIND]}...

  | OUTPUT {file-name-1 [WITH NO REWIND]}...

  | I-O {file-name-1}...

  | EXTEND {file-name-1}...

 }... 

[END-OPEN]


Syntax rules

  1. The EXTEND phrase must not be used for multi-file volumes (see section "I-O-CONTROL paragraph").
  2. EXTEND may be specified only for files for which no LINAGE clause has been specified.
  3. A file-name must not appear more than once in an OPEN statement.
  4. The I-O phrase is permitted for disk storage files only.
  5. The files specified in a given OPEN statement may have different organizations or access modes.
  6. In the case of line sequential files, the only permissible open modes are OPEN INPUT and OPEN OUTPUT without the specifications REVERSED and NO REWIND.

Format 2 for relative and indexed file organization


OPEN {  INPUT {file-name-1}...

  | OUTPUT {file-name-1}...

  | I-O {file-name-1}...

  | EXTEND {file-name-1}...

 }...

[END-OPEN]


Syntax rules

  1. The same file-name must not appear more than once in an OPEN statement.
  2. The files specified in a given OPEN statement need not all have the same organization or access mode.
  3. The EXTEND phrase may be specified only for files with sequential access.

General rules

For sequential, relative and indexed file organization:

  1. After successful execution of an OPEN statement, the file specified by file-name-1 is available in the open mode.
  2. After successful execution of an OPEN statement, the associated record area is available to the program. Only one record area exists for an external file; this area is available to all programs that describe this file.
  3. Before successful execution of an OPEN statement for a file, no statement (except for a SORT or MERGE statement with the USING or GIVING phrase) may be executed that would either explicitly or implicitly reference that file.
  4. INPUT means that the file is to be processed as an input file (input mode).
  5. OUTPUT indicates that the file is to be processed as an output file (output mode).
  6. I-O indicates that input and output operations (i.e. read, write and update operations) are to be performed on the file (update mode). Since this phrase implies the existence of the file, it cannot be used if the file is being initially created.
  7. The EXTEND phrase positions the file immediately after the last logical record in the file. For sequentially organized files, this is the last record written in the file; for relative organization, the record with the highest relative key, and for indexed file organization, the record with the highest value of the primary key. Subsequent WRITE statements for this file causes records to be appended to the file exactly as if it had been opened in OUTPUT mode (extend mode).
  8. All of the INPUT, OUTPUT, I-O or EXTEND phrases may be used, within the same program, in different OPEN statements for a given file. Following the initial execution of an OPEN statement for a file, each subsequent OPEN statement for the same file must be preceded by the execution of a CLOSE statement. The LOCK phrase must not be specified in this CLOSE statement.
  9. The minimum and maximum record lengths for a file are defined when the file is created and must not be modified subsequently.
  10. If an optional file does not exist, successful execution of an OPEN statement with I-O or EXTEND phrase causes the file to be created.
  11. After execution of an OPEN statement, the contents of the data item indicated in the FILE STATUS clause (if specified) will be updated (see section "FILE STATUS clause").
  12. If more than one file-name is specified, the result is the same as if a separate OPEN statement had been written for each file-name.
  13. If an optional file opened with OPEN INPUT is not present then the input/output status is set to the corresponding value.
  14. If files are opened with INPUT or I-O then the following applies:
    • In the case of relative and sequential files, the file position indicator is set to the first record,
    • In the case of indexed files, the file position indicator is set to the smallest possible value for the primary record key.

    For sequentially organized files, the following also applies:

  15. REVERSED indicates that records in the file are to be read in reversed order, i.e. starting with the last record of the file.

    Note:
    The REVERSED phrase should not be specified for a file with nonstandard labels unless the last such label is followed by a tape marker. In all other cases, the system will read label records as if they were records.

  16. NO REWIND may be specified for a tape file or for a disk storage file which was opened OUTPUT. The actions taken for tape and disk storage files are listed below:

    Tape files
    NO REWIND indicates that the tape reel is not to be rewound when the file is opened.

    Disk storage files
    NO REWIND indicates that no records existing on the file are to be overwritten. NO REWIND exists only for reasons of compatibility. OPEN OUTPUT WITH NO REWIND has the same function as OPEN EXTEND.

  17. If the storage medium containing the file permits the rewind function, the following rules apply:
    1. If neither the REVERSED, nor the EXTEND, nor the NO REWIND phrase is specified, execution of the OPEN statement causes the file to be positioned at its beginning.
    2. If the NO REWIND phrase is specified, execution of the OPEN statement does not cause the file to be repositioned; instead, the file is expected to be at its beginning already.
    3. If the REVERSED phrase is specified, the records of the file are made available in reversed order; that is, starting with the last record of the file.

  18. Label handling procedures are performed by the OPEN statement for all files, except those for which LABEL RECORDS ARE OMITTED is specified in the file description entry.

    If the INPUT phrase of the OPEN statement is specified, the following steps are taken:

    1. If system labels are present, they are checked.

    2. If user labels or nonstandard labels are present and an applicable USE procedure is declared, that USE procedure is executed.

    3. The file is positioned so that the first record can be read.

      If the OUTPUT phrase of the OPEN statement is supplied, execution takes place as follows:

    4. If standard labels are specified for the file, they are created and written.

    5. If an applicable USE procedure is declared, it is executed; and user or nonstandard labels are written.

    6. The record area is made available to the program in order to receive data.

      If the I-O phrase of the OPEN statement is specified, the following steps are taken:

    7. If system labels are present, they are checked.

    8. If user labels are present and an applicable USE procedure is declared, that USE procedure is executed.

    9. The file is positioned for data read or replacement operations.

      If the EXTEND phrase as well as the LABEL RECORDS STANDARD/data-name clause are specified for an OPEN statement, then execution of the OPEN statement involves the following steps:

    10. The file header labels are processed only if it is a single-reel or single-volume file.

    11. The reel/volume header labels on the last existing reel/volume are processed as in the case of the OPEN statement with INPUT phrase.

    12. The existing file trailer labels are processed as in the case of the OPEN statement with INPUT phrase. These label records are then deleted.

    13. Further processing is then the same as with OPEN OUTPUT.

    Overview of the statements permitted in OPEN mode



    ACCESS clause



    Statement

    Open mode

    INPUT

    OUTPUT

    I-O

    EXTEND

    SEQUENTIAL

    READ

    R,I,S,L


    R,I,S


    WRITE


    R,I,S,L


    R,I,S

    REWRITE

    R,I,S


    START

    R,I


    R,I


    DELETE



    R,I


    RANDOM

    READ

    R,I


    R,I


    WRITE


    R,I

    R,I


    REWRITE



    R,I


    START





    DELETE



    R,I


    DYNAMIC

    READ

    R,I


    R,I


    WRITE


    R,I

    R,I


    REWRITE



    R,I


    START

    R,I


    R,I


    DELETE



    R,I


    Table 30: Permitted input/output statements in each OPEN mode

The permitted entries are identified as follows:

S

for sequential file organization

L

for line-sequential file organization

R

for relative file organization

I

for indexed file organization