Macros
• Callable modules of program code
Defining Macros - Syntax
DEFINE .
ENDDEFINE.
Calling Macros - Syntax
--------------------------------------------------------------------------------------------
Example:
REPORT demo_mod_tech_macros.
DATA: result TYPE i,
n1 TYPE i VALUE 5,
n2 TYPE i VALUE 6.
DEFINE operation.
result = &1 &2 &3.
output &1 &2 &3 result.
END-OF-DEFINITION.
DEFINE output.
write: / 'The result of &1 &2 &3 is', &4.
END-OF-DEFINITION.
operation 4 + 3.
operation 2 ** 7.
operation n2 - n1.
This produces the following output:
The result of 4 + 3 is 7
The result of 2 ** 7 is 128
The result of N2 - N1 is 1
In this example, the two macros operation and output are defined. output is nested in operation. operation is called three times with different parameters. Note how the placeholders &1, &2,... are replaced in the macros.
No comments:
Post a Comment