Specify a list or qualified name using a variable

Variables can be used to specify a list or qualified name.

The value on a parameter may be a list. For example, the Change Library List (CHGLIBL) command requires a list of libraries on the LIBL parameter, each separated by blanks. The elements in this list can be variables:

CHGLIBL LIBL(&LIB1 &LIB2 &LIB3)

When variables are used to specify elements in a list, each element must be declared separately:

DCL VAR(&LIB1) TYPE(*CHAR) LEN(10) VALUE(QTEMP)
DCL VAR(&LIB2) TYPE(*CHAR) LEN(10) VALUE(QGPL)
DCL VAR(&LIB3) TYPE(*CHAR) LEN(10) VALUE(DISTLIB)
CHGLIBL LIBL(&LIB1 &LIB2 &LIB3)

Variable elements cannot be specified in a list as a character string:

Incorrect:
DCL   VAR(&LIBS) TYPE(*CHAR) LEN(20) +
      VALUE('QTEMP QGPL DISTLIB')
CHGLIBL LIBL(&LIBS)

When presented as a single character string, the system does not view the list as a list of separate elements, and an error will occur.

You can also use variables to specify a qualified name, if each qualifier is declared as a separate variable:
DCL VAR(&PGM) TYPE(*CHAR) LEN(10)
DCL VAR(&LIB) TYPE(*CHAR) LEN(10)
CHGVAR VAR(&PGM) VALUE(MYPGM)
CHGVAR VAR(&LIB) VALUE(MYLIB)
.
.
.
DLTPGM PGM(&LIB/&PGM)
ENDPGM

In this example, the program and library name are declared separately. The program and library name cannot be specified in one variable, as in the following example:

Incorrect:

DCL VAR(&PGM) TYPE(*CHAR) LEN(11)
CHGVAR VAR(&PGM) VALUE('MYLIB/MYPGM')
DLTPGM PGM(&PGM)

Here again the value is viewed by the system as a single character string, not as two objects (a library and an object). If a qualified name must be handled as a single variable with a character string value, you can use the built-in function %SUBSTRING and the *TCAT concatenation function to assign object and library names to separate variables.

Related tasks
Define commands
Related reference
%SUBSTRING built-in function