Sunday, June 8, 2008

SAP ABAP Macros

SAP ABAP Macros

ABAP Macro is basically a Modularization Technique. Some important points to remember about ABAP Macros are as follows.

Structure of a Macro.

DEFINE <Macro Name>
      STATEMENTS
END-OF-DEFINITION
___________________________________________

  • The Macro Definition should occur before the Macro is used.
  • All the statements used in the Macro should be defined between the DEFINE and END-OF-DEFINITION.
  • The statements defined in the Macro can hold not more than 9 place holders (&1, &2, &3,&4,......&8,&9)
  • Basically a Macro does not belong to the DEFINITION part of the program
  • Any ABAP program has PROCESSING BLOCKS and the DEFINE STATEMENT in a MACROS is not interpreted before the PROCESSING BLOCKS in the program
  • MACROS are NOT OPERATIONAL STATEMENTS.
  • A MACRO cannot call itself
  • Another MACRO can be called within a MACRO
_____________________________________________________

Examples of Macro

REPORT ZEX_MACRO .

* Parameter Declaration
Parameters: d_num1 type i,
            d_num2 type i.

* Data Declaration
DATA: d_res TYPE i.

* This Macro performs the operation
DEFINE operation.
  d_res = &1 &2 &3.
  doit   &1 &2 &3 d_res.
END-OF-DEFINITION.

* This Macro gives the result
DEFINE doit.
  write: / 'The result of &1 &2 &3  is', &4.
END-OF-DEFINITION.


operation d_num1 - d_num2.

operation d_num1 + d_num2.

operation d_num1 * d_num2.


See Also: Function Modules in ABAP
           SAP ABAP RFCs
           SAP ABAP BAPIS
           ABAP Subroutines



See Also