Loading...
Select Version
You can access an environment variable using the ACCEPT or DISPLAY statements.
The names of environment variables are defined using format 4 in the DISPLAY statement. Format 5 of the ACCEPT statement is required in order to access the contents of environment variables.
At system level, the environment variables must be set up using an SDF-P variable.
Example 8-5
Accessing an environment variable
/SET-VAR TSTENV='AAAA BBB CC D'
/START-PROGRAM ...
Program excerpt:
IDENTIFICATION DIVISION.
...
SPECIAL-NAMES.
ENVIRONMENT-NAME IS ENV-NAME
ENVIRONMENT-VALUE IS ENV-VAR
TERMINAL IS T
...
WORKING-STORAGE SECTION.
01 A PIC X(15).
...
PROCEDURE DIVISION.
...
DISPLAY "TSTENV" UPON ENV-NAME
ACCEPT A FROM ENV-VAR
ON EXCEPTION DISPLAY "ENVIRONMENT 'TSTENV' IS UNKNOWN!" UPON T
END-DISPLAY
NOT ON EXCEPTION DISPLAY "VALUE IS:" A UPON T
END-DISPLAY
END-ACCEPT
The exception condition appears with every failed access. Causes of a failed access can be, for example:
missing SET-VAR command
content of the variable is longer than the receiving field