Compaq COBOL AAQ2G1FTK User Manual

Page 198

Advertising
background image

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

On Tru64 UNIX, with this code OPEN would create a file with the name
"/usr/filename.dat".

Establishing Device and File Independence with Logical Names

On OpenVMS, logical names let you write programs that are device and file
independent and provide a brief way to refer to frequently used files.

You can assign logical names with the ASSIGN command. When you assign a
logical name, the logical name and its equivalence name (the name of the actual
file or device) are placed in one of three logical name tables; the choice depends
on whether they are assigned for the current process, on the group level, or on
a systemwide basis. See the OpenVMS DCL Dictionary for more information on
DCL and a description of logical name tables.

To translate a logical name, the system searches the three tables in this order:
( 1 ) process, ( 2 ) group, ( 3 ) system. Therefore, you can override a systemwide
logical name by defining it for your group or process.

Logical name translation is a recursive procedure: when the system translates
a logical name, it uses the equivalence name as the argument for another
logical name translation. It continues in this way until it cannot translate the
equivalence name.

Assume that your program updates monthly sales files (for example, JAN.DAT,
FEB.DAT, MAR.DAT, and so forth). Your SELECT statement could look like
either of these:

SELECT SALES-FILE ASSIGN TO "MOSLS"

SELECT SALES-FILE ASSIGN TO MOSLS

To update the January sales file, you can use this ASSIGN command to equate
the equivalence name JAN.DAT with the logical name MOSLS:

$ ASSIGN JAN.DAT MOSLS

To update the February sales file, you can use this ASSIGN command:

$ ASSIGN FEB.DAT MOSLS

In the same way, all programs that access the monthly sales file can use the
logical name MOSLS.

To disassociate the relationship between the file and the logical name, you can
use this DEASSIGN command:

$ DEASSIGN MOSLS

If MOSLS is not set as a logical name, the system uses it as a file specification
and looks for a file named MOSLS.DAT.

Using Environment Variables for File Specification

On Tru64 UNIX, environment variables can be used as aliases for file specification
at run time. File name resolution follows these rules:

Use contents of the ASSIGN TO clause or VALUE OF ID clause to find a
match against an environment variable.

If a match is found, substitute the value of the environment variable in the
construction of the file specification.

If a match was not found, take the file name as specified.

6–18 Processing Files and Records

Advertising