Compaq COBOL AAQ2G1FTK User Manual

Page 200

Advertising
background image

Processing Files and Records
6.2 Identifying Files and Records from Within Your Compaq COBOL Program

PROCEDURE DIVISION.
P0. OPEN OUTPUT F-DISK.

CLOSE F-DISK.

PE. STOP RUN.
END PROGRAM ENVVAR-EXAMPLE2.

Example 6–12, on OpenVMS Alpha, would produce a file with the name
‘‘ENVTEST.DAT’’. On Tru64 UNIX, ‘‘SYS$SCRATCH:’’ has no meaning because
it is a OpenVMS Alpha logical. OpenVMS Alpha logicals are not defined on
Tru64 UNIX. However, the ‘‘SYS$SCRATCH:’’ in the ASSIGN clause can be
defined as an environment variable with the following command:

% setenv ’SYS$SCRATCH:’ ./

This would make ‘‘SYS$SCRATCH’’ point to the home directory. This can be used
for any OpenVMS logicals used in the Compaq COBOL source. When you declare
an environment variable you should be careful to match the case of what is in the
Compaq COBOL source with the setenv(3) line.

6.2.2 Specifying File Organization and Record Access Mode

Your program must state—either explicitly or implicitly—a file’s organization
and record access mode before the program opens the file. The Environment
Division ORGANIZATION and ACCESS MODE clauses, if present, specify these
two characteristics.

In a Compaq COBOL program, each file is given a file name in a separate
Environment Division SELECT statement. The compiler determines the file
organization from the SELECT statement and its associated clauses.

For relative and indexed files, you must specify the ORGANIZATION IS
RELATIVE or the ORGANIZATION IS INDEXED phrase, respectively. For
sequential files you need not specify the ORGANIZATION IS SEQUENTIAL
phrase. For line sequential files you must explicitly declare ORGANIZATION
IS LINE SEQUENTIAL. When you omit the ORGANIZATION IS clause the file
organization is sequential.

The ASSIGN clause, in the SELECT statement, associates the file name with a
file specification. The file specification points the operating system to the file’s
physical and logical location on a specific hardware device.

The SELECT statement and the ASSIGN clause are further described in
Section 6.2.1. For further reference, see the Compaq COBOL Reference Manual.

Each file is further described with a file description (FD) entry in the Data
Division File Section. The FD entry is followed immediately by the file’s record
description.

You can specify additional file characteristics in the Environment and Data
Divisions as follows:

Use the Environment Division APPLY clause to specify file characteristics
such as lock-holding, file extension factors, and preallocation factors. (See
Chapter 15.)

Use file description entries to specify record format and record blocking.

Use record description entries to specify physical record size or sizes.

6–20 Processing Files and Records

Advertising