A macro can appear anywhere and can be repeated any number of times in an application program.
Each time the software encounters a call to the macro, it substitutes the current character string value of the macro. Substitution takes place one command at a time, before each command is executed. To view these substitutions as they occur, issue a SET LEXTRACE ON command.
Consider a program called ShowSubstitution that contains the following line:
list #<1> Employees # <2> LsatName = ‘#<3>‘ #
If the commands shown below were used to execute ShowSubstitution
ShowSubstitution 2 where Smith
then the LIST command shown above would be interpreted as
list 2 Employees where LastName = ‘Smith’ Sorted by DeptNum
Avoiding Macro Substitution
To use a character literal that could be mistaken for a macro – that is, the character literal contains the number sign and the macro name delimiters (#<1> or #
For example, in the command
output ‘The #
output ‘The in box is:’
If the escape character precedes the number sign, the number sign is taken as a literal character. For #<1> and #
output ‘The #
The character string that a macro represents can contain references to other macros.
The software automatically performs multiple rounds of substitution when macros are nested outside quoted strings. If a nested macro appears inside a quoted string, macro substitution occurs only one.
Consider two macros
Note the use of the backslash () to avoid macro substitution in the assignment to
The values of the macros becomes
With this arrangement, the command
which in turn becomes
On the other hand, the command
is processed as
output ‘ out#