Monday, November 21, 2011

Open & Close Statements


OPEN STATEMENT

Syntax:         OPEN OPENMODE FILENAME
OPENMODE can be INPUT OUTPUT I-O EXTEND
INPUT           - File can be used ONLY-FOR-READ purpose.
OUTPUT         - File can be used ONLY-FOR-WRITE purpose.
I-O               - File can be used FOR READ, WRITE and REWRITE purpose.
EXTEND         - File can be used FOR appending records using WRITE.


CLOSE statement

The used files are closed using CLOSE statement. If you don’t close the files, the completion of the program closes all the files used in the program.
Syntax:         CLOSE FILENAME

OPEN and CLOSE for TAPE files - Advanced

If more than one file is stored in a reel of tape, it is called as multi-file volume. When one file is stored in more than one reel of tape, it is called as
multi-volume label. One reel is known as one volume. When the end of one volume is reached, automatically the next volume opens. So there is no special control is needed for multi volume files.

OPEN INPUT file-1 [WITH NO REWIND | REVERSED]
OPEN OUTPUT file-2 [WITH NO REWIND]
CLOSE file-3 [{REEL|UNIT} [WITH NO REWIND| FOR REMOVAL]
CLOSE file-3 [WITH NO REWIND|LOCK]

UNIT and REEL are synonyms.
After opening a TAPE file, the file is positioned at its beginning. When opening the file if the clause REVERSED is coded, then the file can be read in the REVERESE direction. (Provided hardware supports this feature)

When you close the file, the tape is normally rewound. The NO REWIND clause specifies that the TAPE should be left in its current position.                  


CLOSE statement with REEL option closes the current reel alone. So the next READ will get the first record of next REEL. This will be useful when you want skip all the records in the first reel after n number of records processing.

Since TAPE is sequential device, if you create multiple files in the same TAPE, then before opening the second file, first file should be closed. At any point of time, you can have only one file is active in the program. In addition to this, you have to code MULTIPLE FILE clause in the I-O control paragraph of environment division.
MULTIPLE FILE TAPE CONTAINS      OUT-FILE1 POSITION 1
OUT-FILE3 POSITION 3.
The files OUT-FILE1 and OUT-FILE3 used in the program are part of a same TAPE and they exist in first and third position in the tape. Alternatively, this information can be passed from JCL using LABEL parameter.

No comments:

Post a Comment