About Macros

About Macros

Welcome to our Knowledge Base

Documentation | Blog | Demos | Support

< All Topics
Print

About Macros

A macro is a dynamically declared name that represents a character string. When a macro call is encountered in an application program the macro call is replaced by the current character string value of the macro. Macros are sometimes called replacement parameters or substitution variables.

The following topics discuss how to work with macros in applications:

  • Availability of macros
  • How macros acquire values
  • Macro Substitution
  • Macros and Compiled Programs

The Availability of Macros

You can declare two different kinds of macros during an application session:

  • global macros
  • local macros

Global Macros

The name declaration for a global macro uses the following syntax:

<name>

where

namea valid identifying name for the macro
< and >macro name delimiters make the macro easy to distinguish

After a global macro is declared, you can reuse it in any application program for the duration of the application session. When the session ends, the macro is no longer available.

Local Macros

The name declaration for a global macro uses the following syntax:

<n>

where:

na number from 0 to 9
< and >macro name delimiters make the macro easy to distinguish

Every procedure has its own set of ten local macros, <0> through <9>. You can use a local macro only while the procedure to which it belongs continues to execute. Once execution control transfers elsewhere, the local macros particular to that procedure are discarded.

Examples

Consider a global macro, . If you define to represent the character string list all, then the statement

# Documents

is interpreted as

list all Documents

# is the macro call that is replaced by the character string the represents, list all. The number sign (#) is the macro call indicator.

If you redefine to represent the character string ENT, then the statement

list #s format #Name

is interpreted as

list ENTs format ENTName

Macros and Compiled Programs

Macro substitution takes place only when the software is parsing a source (uncompiled) program.

During compilation, the software parses the source code and performs macro substitution based on current macro values. The resulting commands are then compile and stored in compiled form.

When the compiled program is executed, its source code is not parsed again. Therefore, changes to macro values in the interim are not reflected when the compiled program is executed.

For this reason, programs that use macros should not normally be compiled.

Was this article helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.

Leave a Reply

Your email address will not be published. Required fields are marked *

en_CAEnglish