The OPEN statement opens a specified file.

figure syntax open
OPEN Statement

open-options:

image

Component Description

FILE

File to open.

FILE attribute

Refer to File.

TITLE

DD name of an external dataset described in a JCL.

LINESIZE

Length of a line. (Default value: 120)

If a stream length exceeds LINESIZE, the next line will be used from the first column.

This option can be used only for STREAM OUTPUT files.

PAGESIZE

Number of lines in a page. (Default value: 60)

If a line exceeds PAGESIZE, the ENDFILE condition will occur.

A new page can start using a PAGE format item or the PAGE option in a PUT statement.

A file can be opened explicitly by using an OPEN statement. An unopened file opens when using a READ, WRITE, REWRITE, DELETE, LOCATE, PUT, or GET statement.

A FILE attribute that was defined during a declaration can be redefined by defining the attribute when explicitly opening a file using an OPEN statement. The following example redefines the FILE attribute using an OPEN statement.

 DECLARE TEST FILE RECORD OUTPUT;
 OPEN FILE(TEST) STREAM INPUT;
 CLOSE FILE(TEST);

 OPEN FILE(TEST);

In the first OPEN statement, TEST has the STREAM and INPUT attributes. Once a file is closed, the FILE attribute is lost and not applied when the file is reopened. Therefore, in the second OPEN statement, TEST has the RECORD and OUTPUT attributes specified in the DECLARE statement.

If the FILE attribute defined during declaration is different from the attribute defined during opening, an error will occur.