How Macros Acquire Values

How Macros Acquire Values

Welcome to our Knowledge Base

Documentation | Blog | Demos | Support

< All Topics
Print

How Macros Acquire Values

A macro acquires a value in one of two ways:

  1. 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
  2. explicitly in a LET or INPUT command (global or local macros), or in a call to a procedure (local macros only)

Implicit Value

If the software encounters a call to a previously unknown macro or an unassigned local macro, it substitutes the null string for the macro.

Example

Suppose the global macro #<NumToDo> has not been previously declared. The command

list #<NumToDo> WaterSamples

processes after replacing #<NumToDo> with a null string. The command executes as

list WaterSamples

Explicit Value

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 <mac1>, <mac2>, and <mac3>, and to the local macro <8>:

let <mac1> = 'Employees where LastName = Smith'
let <mac2> = 'abc'
let <mac3> = 'def'
let <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 <mac> currently represents the character string <abc>. If you attempt to change the assigned value of <mac> by entering

let #<mac> = 'xyz'

the statement is interpreted as

let <abc> = 'xyz'

Instead of <mac> acquiring a new value, a new macro <abc> has been declared.

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:

input <mac1> <mac2> <mac3> <8> <mac4> <7>

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:

<mac1>abc
<mac2>4+3
<mac3>‘3*5’
<8>xyz
<mac4>!
<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:

<1>Employees
<2>5
<3>*
<4>2
<5>Salary/Age
<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:

let <NumToDo> = ''

This command discards the value of the global macro <NumToDo>.

Was this article helpful?
5 out of 5 stars

1 rating

5 Stars 100%
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