613-518-1166 info@zimdatabases.com

ZIM 9 Basics

Macrosubstitution

< All Topics

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

let = ‘Sorted by DeptNum’
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 #) – you must employ the backslash (-escape character) to indicate that the number sign is to be take literally.

For example, in the command

output ‘The # in the box #<1> is:’

# and #<1> are recognized as macros. If they are not intended to be macros and therefore have not been previously defined, they are automatically replaced with the null string. Thus the command becomes

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 # to be taken literally, the output command would read

output ‘The # in box #<1> is:’

Nested Macros

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.

Example

Consider two macros and . The following command could  be used to assign character strings to these macros:

let = ‘put’ = ‘ out#

Note the use of the backslash () to avoid macro substitution in the assignment to .

The values of the macros becomes

put

out#

With this arrangement, the command

# ‘Hello’

becomes

out# ‘Hello’

which in turn becomes

output ‘Hello’

On the other hand, the command

output ‘#

is processed as

output ‘ out#

Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Table of Contents