ABAP Macros [SAP]
ABAP programmers, do you use macros? Create macros, and use them? Macros make the program more readable, organizable, so on.
If you want to reuse the same set of statements more than once in a program, you can include them in a macro. For example, this can be useful for long calculations or complex WRITE statements. You can only use a macro within the program in which it is defined, and it can only be called in lines of the program following its definition.
The following statement block defines a macro macro:
DEFINE makro.
statements
END-OF-DEFINITION.
The facts about macros:
- You must specify complete statements between DEFINE and END-OF-DEFINITION.
- Statements can contain up to nine placeholders &1, &2,…., &9).
- You must define the macro before the point in the program at which you want to use it.
- Macros do not belong to the definition part of the program. This means that the DEFINE statement block is not interpreted before the processing blocks in the program. At the same time, however, macros are not operational statements that are executed within a processing block at runtime. When the program is generated, macro definitions are not taken into account at the point at which they are defined. For this reason, they do not appear in the overview of the structure of processing logic.
- Macros [SAP Help Netwaver 7.0]
March 18th, 2008 at 11:40 pm
I don’t use macros. In ABAP OO I prefer to put stuff into helper methods (private if possible). Macros have the huge disadvantage that you can’t debug the code inside.
March 19th, 2008 at 2:49 pm
@Joerg
You are absolutely right!
Macros cannot be debugged and this is very serious disadvantage.