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 contain records. The file will be replaced by new data.
If the OUTPUT phrase is specified for a file that already contains records and either the SdU or SFS file system is used, the file will be deleted and recreated.
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 information on file sizes, see Compiler limits.
Label processing is not supported. A warning message is issued if any of the following language elements are encountered:
| Opened as | File is available | File is unavailable |
|---|---|---|
| INPUT | Normal open | Open is unsuccessful. (file status 35) |
| INPUT (optional file) | Normal open | Normal open; the first read causes the at end condition or the invalid key condition. (file status 05) |
| I-O | Normal open | Open is unsuccessful. (file status 35) |
| I-O (optional file) | Normal open | Open causes the file to be created. (file status 05) |
| OUTPUT | Normal open; the file contains no records | Open causes the file to be created. |
| EXTEND | Normal open | Open is unsuccessful. (file status 35) |
| EXTEND (optional file) | Normal open | Open causes the file to be created. (file status 05) |
| 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 |