ARTICLE
Inserting Macros
Syntax
macro [p1 p2 ... ].
Effect
If a macro is executed instead of a valid
ABAP keyword , as the first word in an ABAP statement, its statements
are included at this position in the source text. Suitable ABAP words or
operands p1 p2 ... must be transferred to all of the macro's
placeholders. The specified operands p1 p2 ... replace the
placeholders sequentially. The characters are converted to uppercase
(except for the content of character literals).
The ABAP Compiler searches for a macro specified in a program,
first in the preceding source text of the same
compilation unit and then in the
type groups which are used for the
program. Local macros of the program hide macros of the same name in
type groups.
A macro can insert other macros but not itself.
Notes
Previously, a specified macro not defined in the current program was
only searched for in explicitly loaded type
groups using the TYPE-POOLS statement.
The search now covers all usable type groups.
If the ABAP Compiler does not find a specified macro in the
current program or in a type group , it
searches in the TRMAC table. Macros in the TRMAC table
usually follow different name conventions to those in type groups and
therefore nothing should be hidden.
Example
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.
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.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved