Compaq AAQ2G1FTK Marine Radio User Manual


 
Processing Files and Records
6.3 Creating and Processing Files
Example 621 OPEN and CLOSE Statements
.
.
.
OPEN INPUT MASTER-FILE.
OPEN OUTPUT REPORT-FILE.
OPEN I-O MASTER-FILE2
TRANS-FILE
OUTPUT REPORT-FILE2.
CLOSE MASTER-FILE.
CLOSE TRANS-FILE, MASTER-FILE2
REPORT-FILE, REPORT-FILE2.
.
.
.
The OPEN statement must specify one of the following four open modes:
INPUT
OUTPUT
I-O {Not for LINE SEQUENTIAL}
EXTEND
Your choice, along with the file’s organization and access mode, determines which
I/O statements you can use. Sections 6.3.2, 6.3.3, and 6.3.4 discuss the I/O
statements for sequential, relative, and indexed files, respectively. Section 12.8.4,
Case Sensitivity on Tru64 UNIX and Windows NT explains the importance of
attention to case.
When your program performs an OPEN statement, the following events take
place:
1. The I/O system builds a file specification by using the contents of the VALUE
OF ID clause, if any, to alter or complete the file specification in the ASSIGN
clause. Logicals and environment variables are translated.
2. The I/O system checks the file’s current status. If the file is unavailable, or
if it was closed WITH LOCK, the OPEN statement fails. (See Chapter 8 for
information on file sharing.)
3. If the file specification names an invalid device, or contains any other errors,
the I/O system generates an error message and the OPEN statement fails.
4. The I/O system takes one of the following actions if it cannot find the file:
a. If the file’s OPEN mode is OUTPUT, the file is created.
b. If the file’s OPEN mode is EXTEND, or I-O, the OPEN statement fails,
unless the file’s SELECT clause includes the OPTIONAL phrase. If the
file’s SELECT clause includes the OPTIONAL phrase, the file is created.
c. If the file’s OPEN mode is INPUT, and its SELECT clause includes the
OPTIONAL phrase, the OPEN statement is successful. The first read on
that file causes the AT END or INVALID KEY condition.
d. If none of the previous conditions is met, the OPEN fails and the
Declarative USE procedure (if any) gains control. If no Declarative
USE procedure exists, the I/O system aborts the program.
5. If the file’s OPEN mode is OUTPUT, and a file by the same name already
exists, a new version is created.
Processing Files and Records 625