Processing Files and Records
6.2 Identifying Files and Records from Within Your Compaq COBOL Program
On Tru64 UNIX, you can also use the literal or alphanumeric item to specify a
run-time environment variable set. See
setenv(3)
in the reference page.
♦
Example 6–11 and the commands that follow it illustrate how to use the ASSIGN
TO clause in conjunction with an environment variable.
Example 6–11 Using Environment Variables for File Specification
IDENTIFICATION DIVISION.
PROGRAM-ID. ENVVAR-EXAMPLE.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT F-DISK ASSIGN TO "MYENV".
DATA DIVISION.
FILE SECTION.
FD
F-DISK.
01
DAT-RECORD PIC X(100).
PROCEDURE DIVISION.
P0. OPEN OUTPUT F-DISK.
CLOSE F-DISK.
PE. STOP RUN.
END PROGRAM ENVVAR-EXAMPLE.
% cobol -o envtest envvar-example.cob
% setenv MYENV hello.dat
% envtest
% ls *.dat
hello.dat
% unsetenv MYENV
% envtest
% ls MY*
MYENV
The flexibility of setting environment variables at run time will help you migrate
OpenVMS Alpha applications to Tru64 UNIX because you can define environment
variables that access files in a way similar to that in which you access files using
logical names on OpenVMS systems.
Example 6–12 Using Environment Variables
IDENTIFICATION DIVISION.
PROGRAM-ID. ENVVAR-EXAMPLE2.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT F-DISK ASSIGN TO "SYS$SCRATCH:envtest.dat".
DATA DIVISION.
FILE SECTION.
FD
F-DISK
VALUE OF ID "SYS$DISK:".
01
DAT-RECORD PIC X(100).
Processing Files and Records 6–19
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......