DEFINE macro.
... &1 ... &9 ...
END-OF-DEFINITION.
The statement DEFINE defines a macro. Naming conventions apply to the name macro and you cannot use ABAP words. Between the statements DEFINE and END-OF-DEFINITION, you can use any number of complete ABAP statements, with the exception of DEFINE, END-OF-DEFINITION, and program-initiating statements. These statements constitute a section of source code that can be inserted into a program under the name macro. The definition of a macro is not restricted to the limits of processing blocks.
The validity of a macro is defined by its position in the source code. It can be inserted at any position after END-OF-DEFINITION. If another macro is defined with the same name, it overwrites the previous macro from its new position.
Within a macro, you can use up to nine placeholders &1 ... &9 instead of ABAP words and operands. These placeholders must be replaced by fixed words when the macro is inserted.
Inserting Macros
macro [p1 p2 ... ].
If a previously defined macro is listed as the first word in an ABAP statement instead of a valid ABAP keyword, then these statements are inserted in the source code at this position. Appropriate ABAP words or operands p1 p2 ... must be specified for all placeholders of the macro. p1 p2 ... replace the placeholders literally, one after the other.
A macro can insert other macros, but not itself.
In this example, a macro write_frame, which draws a frame around a placeholder &1 in a list, is defined and then implemented.
DATA: x TYPE i, y TYPE i, l TYPE i.
DEFINE write_frame.
x = sy-colno. y = sy-linno.
WRITE: '|' NO-GAP, &1 NO-GAP, '|' NO-GAP.
l = sy-colno - x.
y = y - 1. SKIP TO LINE y. POSITION x.
ULINE AT x(l).
y = y + 2. SKIP TO LINE y. POSITION x.
ULINE AT x(l).
y = y - 1. x = sy-colno. SKIP TO LINE y. POSITION x.
END-OF-DEFINITION.
SKIP.
write_frame 'In a frame!'.