Friday, September 4, 2009

The OPEN Statement

The OPEN Statement
Syntax
Format
OPEN { INPUT {file-name-1} ...
OUTPUT {file-name-2} ...
I-O {file-name-3} ...
EXTEND {file-name-4} ... } ...

Description
The OPEN statement is used to prepare a file for processing. A file must be open before any other operation is performed on it. INPUT means the records which exist in the file will be made available to the program. OUTPUT means that records will be created by the program and entered into the file. I-O means both input and output operations will be performed. EXTEND means that records will be created by the program and added to the end of an existing file.

Tips
1. If there is a file status associated with the file, it will be set after the CLOSE is execute to indicate the result of the CLOSE. A value of "00" means successful.
2. Any file mentioned must be the subject of a SELECT statement and a file description (FD). Files opened for input, input/output, or extend should exist prior to executing the OPEN statement.
3. When used in a program with a SORT statement, the sort file itself can never be opened and the USING and GIVING file, if any, may not be open at the time the SORT statement is executed.
4. Use the CLOSE statement to terminate processing on the files when you are through with them