Variable Substitution

Using the LET command, you can define a word that represents a variable phrase. A variable phrase contains placeholder symbols (carets) to indicate missing elements in the phrase. This allows you to give a phrase different meanings in different requests. Placeholders can be parts of words within phrases. They can also be used to represent system commands.

Placeholders can be numbered or unnumbered. If the placeholders are not numbered, then they are filled from left to right: the first word in the request after the LET-defined word fills the first placeholder, the second word fills the second placeholder, and so on to the last placeholder. If they are numbered, the placeholders are filled in numerical order. If you do not supply enough words to fill all the placeholders, the extra placeholders are null.

Example: Making a Variable Substitution

The command

LET UNDERSCORE = ON < > UNDER-LINE

contains one placeholder. After issuing this command, you can use the word UNDERSCORE in a request:

TABLE FILE EMPLOYEE
PRINT CURR_SAL BY EMP_ID BY HIRE_DATE
UNDERSCORE EMP_ID
END

The field name following the LET-defined word supplies the missing value to the placeholder. In the example, EMP_ID follows the defined word UNDERSCORE. This field name is inserted in the placeholder and translates UNDERSCORE EMP_ID as:

ON EMP_ID UNDER-LINE

Example: Making Multiple Variable Substitutions (Unnumbered)

Issuing the LET command

LET TESTNAME = WHERE LAST_NAME IS < > OR < > OR < >

and then including the following line in a request

TESTNAME 'MCKNIGHT' 'STEVENS' 'BLACKWOOD'

translates the line as:

WHERE LAST_NAME IS 'MCKNIGHT' OR 'STEVENS' OR 'BLACKWOOD'

Notice that the variable phrase needs no placeholder at the end, and could also be code as WHERE LAST_NAME IS <> OR <>. Once all the placeholders are filled, the rest of the definition follows. In this example, the words MCKNIGHT and STEVENS would fill the two placeholders. BLACKWOOD would be left over, so it would follow the variable phrase.

If you do not supply enough words to fill in all the placeholders, the extra placeholders are null. For example, issuing this LET command

LET TESTNAME = WHERE LAST_NAME IS < > OR < > OR

and then entering this command

TESTNAME 'MCCOY'

translates the statement into:

WHERE LAST_NAME IS 'MCCOY' OR OR

This statement is illegal and produces an error message.

Example: Making Multiple Variable Substitutions (Numbered)

The following LET command contains numbered placeholders:

LET TESTNAME = WHERE LAST_NAME IS <1> OR <2> OR <3>

Therefore, the following line

TESTNAME 'STEVENS' 'MCKNIGHT' 'BLACKWOOD'

is translated as follows:

WHERE LAST_NAME IS 'STEVENS' OR 'MCKNIGHT' OR 'BLACKWOOD'

If two placeholders have the same number, both placeholders are filled with the same word. For example, if you issue this LET command

LET RANGE = SUM MAX.<1> AND MIN.<1>

and this line

RANGE SALARY

the translated statement is:

SUM MAX.SALARY AND MIN.SALARY

Example: Making a Variable Substitution in a Phrase

Issuing the following LET command

LET BIGGEST = MAX.< >

and entering the line

WRITE BIGGEST SALARY

translates the statement as:

WRITE MAX.SALARY

Example: Defining a System Command

Each of the following LET commands define a system command:

LET ALFOC = TSO ALLOC F(< >) DA(< >.FOCUS) SHR
LET LISTMEM = TSO LISTDS < > MEMBERS

Information Builders