The OPEN statement initiates the processing of files. It also checks or writes labels, or both.
Format 1: OPEN statement for sequential files >>-OPEN---------------------------------------------------------> .---------------------------------------------------------. | .------------------------------------------. | V V | | >----+-INPUT----file-name-1--+-------------------------+-+-+-+->< | | (1) | | | +-REVERSED----------------+ | | | (1) | | | '-+------+--NO REWIND-----' | | '-WITH-' | | .--------------------------------------. | | V | | +-OUTPUT----file-name-2--+---------------------+-+----+ | '-+------+--NO REWIND-' | | '-WITH-' | | .-------------. | | V | | +-I-O----file-name-3-+--------------------------------+ | .-------------. | | V | | '-EXTEND----file-name-4-+-----------------------------'
Format 2: OPEN statement for indexed and relative files .-----------------------------. | .-------------. | V V | | >>-OPEN----+-INPUT----file-name-1-+--+-+----------------------->< | .-------------. | | V | | +-OUTPUT----file-name-2-+-+ | .-------------. | | V | | +-I-O----file-name-3-+----+ | .-------------. | | V | | '-EXTEND----file-name-4-+-'
Format 3: OPEN statement for line-sequential files .-----------------------------. | .-------------. | V V | | >>-OPEN----+-INPUT----file-name-1-+--+-+----------------------->< | .-------------. | | V | | +-OUTPUT----file-name-2-+-+ | .-------------. | | V | | '-EXTEND----file-name-4-+-'
The phrases INPUT, OUTPUT, I-O, and EXTEND specify the mode to be used for opening the file. At least one of the phrases INPUT, OUTPUT, I-O, or EXTEND must be specified with the OPEN keyword. The INPUT, OUTPUT, I-O, and EXTEND phrases can appear in any order.
Do not specify OUTPUT for files that:
If the OUTPUT phrase is specified for a file that already contains records, the data set must be defined as reusable and cannot have an alternate index. The records in the file will be replaced by the new data and any ALTERNATE RECORD KEY clause in the SELECT statement will be ignored.
The I-O phrase is not valid for line-sequential files.
The EXTEND phrase is allowed for sequential access files only if the new data is written in ascending sequence. The EXTEND phrase is allowed for files that specify the LINAGE clause.
For QSAM files, do not specify the EXTEND phrase for a multiple file reel.
If you want to append to a file, but are unsure if the file exists, use the SELECT OPTIONAL clause before opening the file in EXTEND mode. The file will be created or appended to, depending on whether the file exists.
If the concept of reels has no meaning for the storage medium (for example, a direct access device), the REVERSED and NO REWIND phrases do not apply.
When OPEN REVERSED is specified, the record format must be fixed.
If the PASSWORD clause is specified in the file-control entry, the password data item must contain a valid password before the OPEN statement is executed. If a valid password is not present, OPEN statement execution is unsuccessful.
If label records are specified for the file when the OPEN statement is executed, the labels are processed according to the standard label conventions, as follows:
When label records are specified but not present, or are present but not specified, execution of the OPEN statement is unpredictable.
| Opened as | 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 the 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. |
| Statement | Input open mode | Output open mode | I-O open mode | Extend open mode |
|---|---|---|---|---|
| READ | X | X | ||
| WRITE | X | X | ||
| REWRITE | X |
In the following table, an 'X' indicates that the specified statement, used in the access mode given for that row, can be used with the open mode given at the top of the column.
| File 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 | X | |||
| DELETE | X | ||||
| Random | READ | X | X | ||
| WRITE | X | X | |||
| REWRITE | X | ||||
| START | |||||
| DELETE | X | ||||
| Dynamic | READ | X | X | ||
| WRITE | X | X | |||
| REWRITE | X | ||||
| START | X | X | |||
| DELETE | X |
In the following table, an 'X' indicates that the specified statement can be used with the open mode given at the top of the column.
| Statement | Input open mode | Output open mode | I-O open mode | Extend open mode |
|---|---|---|---|---|
| READ | X | |||
| WRITE | X | X | ||
| REWRITE |