1. OPEN

The OPEN statement initiates file processing.

  • Format 1

    figure pd open format1 sequential files
    OPEN Statement Format 1
  • Format 2

    figure pd open format2 indexed and relative files
    OPEN Statement Format 2
  • Format 3

    figure pd open format3 line sequential files
    OPEN Statement Format 3

The following items are specified in the statement.

  • INPUT

    • Opens input files.

  • OUTPUT

    • Opens output files.

    • Can be used for newly created files. If the file for which the OUTPUT phrase is to be used contains records, the existing records are removed to open the file.

  • I-O

    • Opens both input and output files.

  • EXTEND

    • Opens an output file to append to existing records or to create a new file.

    • If the file already exists, records are added to the existing records, and if not, a new file is created.

  • file-name-1, file-name-2, file-name-3 , file-name-4

    • Describes files to be opened.

    • Must be described in the FD entry.

  • REVERSED, NO REWIND

    • Only applies to tape files.

General Rules

The OPEN INPUT statement or the OPEN I-O statement sets the file position indicator on the position of the first record.

If the EXTEND phrase is specified, the OPEN statement sets the file position after the last record of the file. Successive WRITE statements add records as if the file had been opened with OUTPUT. The EXTEND phrase can be specified for a newly created file.

For VSAM files, if there is no record in the file, the file position indicator is set so that the execution result of the READ statement of format 1 causes an AT END condition.

The following tables show the relationship between OPEN modes and the available input/output statements.

  • 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

  • Permissible statements for indexed and relative files

    Fille 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

    DELETE

    X

    Random

    READ

    X

    X

    WRITE

    X

    X

    REWRITE

    X

    START

    DELETE

    X

    Dynamic

    READ

    X

    X

    WRITE

    X

    X

    X

    REWRITE

    X

    START

    X

    X

    DELETE

    X

  • 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

'X' indicates an allowed statement.