ABAP Keyword Documentation →  ABAP − Reference →  Program Layout →  Modularization Statements →  Source Code Modules →  Macros → 

Inserting Macros


macro [p1 p2 ... ].


If a macro is executed as the first word in an ABAP statement instead of a valid ABAP keyword, its content is included at this position in the source code.

To ensure that the program has correct syntax, the included macro must only contain full ABAP statements (except DEFINE and END-OF-DEFINITION) and introductory program statements. These statements create a source code section that is included in the current source code. The statements of a macro are not bound to the limits of processing blocks here.

Suitable ABAP words or operands p1, p2, ... must be passed to all of the placeholders of the macro. The specified operands p1, p2, replace the placeholders sequentially. The characters are converted to uppercase (except for the content of character literals).

ABAP Compiler searches for a macro specified in an ABAP program as follows:

  1. In the preceding source code of the same compilation unit.

  2. In the type groups that can be used for the program. Local macros of the program obscure macros of the same name in type groups.

  3. In the table TRMAC. Macros in the table TRMAC usually follow different name conventions to those in type groups and therefore nothing should be obscured.

A macro can insert other macros but not itself.


In global classes, macros are defined in a dedicated include program and can be found in this program.


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.

DEFINE output.
  write: / 'The result of &1 &2 &3 is', &4.

operation 4 + 3.
operation 2 ** 7.
operation n2 - n1.

Executable Example