How Macros Acquire Values
A macro acquires a value in one of two ways:
- implicitly when the software encounters a call to a previously unknown global macro, or when a local macro is unassigned in a macro call program
- explicitly in a LET or INPUT command (global or local macros), or in a call to a procedure (local macros only)
If the software encounters a call to a previously unknown macro or an unassigned local macro, it substitutes the null string for the macro.
Suppose the global macro
processes after replacing #
You can use the LET and INPUT commands to explicitly assign values to either global or local macros.
You can also explicitly assign values to local macros in a call to a procedure.
LET Command Examples
You can use the LET command to assign the character string value of an expression to a macro.
In the following example, the LET command assigns values to the global macros
<8> = $concat(‘f’, EntName)
You can make any number of assignments in a single LET command. The value assigned to a macro can be the result of a complex value expression.
Do not use the macro call indicator (#) when assigning a value to the macro. If you use the call indicator in an assignment statement, the macro call is replaced by the current character string value of the macro.
For example, suppose the global macro
the statement is interpreted as
INPUT Command Examples
The INPUT command enables the application user to enter one line of data from the terminal. The software resolves the data into a series of values and assigns the values to the expressions listed in the INPUT command. The expressions in the INPUT command can be macros, variables, parameters, and so on, as shown in the following example:
The macro call indicator (#) is not used in the statement, because the INPUT command, like the LET command, is performing value assignments.
The data entered at the terminal by the user is parsed and separated into individual character strings. The strings are assigned to the specified macros, in order. If there are more strings than values, the remaining macros are assigned the null string.
For example, in response to the INPUT command above, the application user could enter
abc 4+3 ‘3*5’ xyz !
If the current delimiter is the space, the macros are assigned values as follows:
|<7>||” (null string)|
Macro Program Call Examples
You can also assign values to local macros in the call to a macro application.
Normally, you call a macro program by issuing a command consisting of the program’s name. However, the program name can be followed by a list of character strings to assign to the local macros belonging to the main procedure in the program.
Any character string is valid, including
- reserved words
- object names
- special characters
- number literals
- character literals
The software reads any characters following the macro program name and separates them into individual character string values, based on the current field delimiter. The first value from the program call is assigned to macro <1>, the second to macro <2>, and so on.
If there are not enough values to be assigned to all local macros, the remaining local macros are assigned the null string.
If there are more than nine values, the first nine are assigned to the local macros <1> to <9>, then all remaining characters in the statement , including the spaces between them, are assigned to local macro <0>.
If a macro program call includes no character strings, all local macros <0> through <9> are assigned the null string.
Suppose ListFields is a macro program called by the command
ListFields Employees * 2 ‘Salary/Age’
If the field delimiter is space, values are assigned to the local macros as follows:
|<6>||” (null string)|
|<7>||” (null string)|
|<8>||” (null string)|
|<9>||” (null string)|
|<0>||” (null string)|
Discarding Macro Values
Once defined, a global macro persists until the end of the application session; a local macro persists until the procedure to which it belongs stops executing.
To explicitly discard a macro value, you can assign the null string to the macro as shown in the following example:
This command discards the value of the global macro