If we want to reuse the same set of statements more than once in a program, we can include them in a macro. We can only use a macro within the program in which it is defined. Macro definition should occur before the macro is used in the program.
We can use the following syntax to define a macro.
DEFINE <macro name>. ... END-OF-DEFINITION.
Demo program using Macro.
*Macro definition DEFINE print. write:/ 'Hello Macro'. END-OF-DEFINITION. WRITE:/ 'Before Using Macro'. print.
Output
We can pass up to 9 placeholders to Macros.
*Macro definition DEFINE print. write:/ 'Hello', &1, &2. END-OF-DEFINITION. WRITE:/ 'Before Using Macro'. print 'ABAP' 'Macros'.
Output