Developing Compaq COBOL Programs
1.3 Developing Programs on OpenVMS Alpha
You provide definitions for the command-line arguments with the
SPECIAL-NAMES paragraph in your program’s Environment Division, and
include ACCEPT and DISPLAY statements in the Procedure Division to parse the
command line and access the arguments. Detailed information about command-
line argument capability is in the ACCEPT and DISPLAY sections in the Compaq
COBOL Reference Manual.
1.3.4.2 Accessing System Logicals at Run Time
You can read and write system logicals at run time through your Compaq COBOL
program.
Example 1–4 allows the user to specify a file specification by putting the directory
in the value of the logical COBOLPATH and the file name in a command-line
argument.
Example 1–4 Accessing Logicals and Command-Line Arguments
IDENTIFICATION DIVISION.
PROGRAM-ID. EXAMPLE.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
SYSERR
IS STANDARD-ERROR
ENVIRONMENT-NAME
IS NAME-OF-LOGICAL
ENVIRONMENT-VALUE
IS LOGICAL-VALUE
ARGUMENT-NUMBER
IS POS-OF-COMMAND-LINE-ARGUMENT
ARGUMENT-VALUE
IS COMMAND-LINE-ARGUMENT.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 howmany-records PIC 9(5).
01 env-dir PIC x(50).
01 file-name PIC x(50).
01 file-spec PIC x(100).
BEGIN.
ACCEPT howmany-records FROM COMMAND-LINE-ARGUMENT
ON EXCEPTION
DISPLAY "No arguments specified"
UPON STANDARD-ERROR
STOP RUN
END-ACCEPT.
DISPLAY "COBOLPATH" UPON NAME-OF-LOGICAL.
ACCEPT env-dir FROM LOGICAL-VALUE
ON EXCEPTION
DISPLAY "Logical COBOLPATH is not set"
UPON STANDARD-ERROR
END-DISPLAY
ACCEPT file-name FROM COMMAND-LINE-ARGUMENT
ON EXCEPTION
DISPLAY
"Attempt to read beyond end of command line"
UPON STANDARD-ERROR
END-DISPLAY
NOT ON EXCEPTION
STRING env-dir file-name delimited by " " into file-spec
DISPLAY "Would have read " howmany-records " records from " file-spec
END-ACCEPT
END-ACCEPT.
Example 1–4 assumes that the logical COBOLPATH is set as follows:
$ define COBOLPATH MYDEV:[MYDIR]
Developing Compaq COBOL Programs 1–49
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......