Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

MACROS in ABAP

$
0
0

Well, it is a very old methodology but still useful in some cases..... for those who are not aware....

 

Macro is just like Sub-routine BUT.... it has some advantages and some dis-advantages.

 

A macro can be used when we want to use the same set of statement multiple times.

 

A macro is either local and can be defined as :

 

DEFINE macro_name.

   statements

END-OF-DEFINITION.

 

A macro can be GLOBAL and the best example is the BREAK statement of ABAP.

 

macro.png

 

Global macros are defined in table TRMAC in SAP and can be used as you use the BREAK statement.

 

The maximum number of parameters that can be passed in a macro are 9.

 

One of the possible example I could think is easy to understand is field catalog.

 

DEFINITION.

 

DEFINE Build_FCat.

    itfieldcat-fieldname  = &1.

    itfieldcat-col_pos     = &2.

    itfieldcat-seltext_l    = &3.

    itfieldcat-emphasize = &4.

    itfieldcat-outputlen   = &5.

    append itfieldcat to itfieldcat.

    clear itfieldcat.

END-OF-DEFINITION.

 

USAGE.

 

  Build_FCat 'EBELN'   '01'  'PO Number'   'X' 10.

  Build_FCat 'EBELP'   '02'  'PO Item'        ' ' 05.

  Build_FCat 'MAKTX'    '03' 'Description'    ' ' 25.

 

Now,

 

Macros don't belong to the definition part of the program. So you cannot debug them and they don't appear also in the debugger.

 

The best use would be to put logic that are complex calculations that you don't want to be disturbed in debug mode

 

Some checks which you want to over ride etc.

 

But in generalized way if used can save you lot of stuffs like using in QCI calculations for OIL material quantities to group it and get the table directly

 

Note : SAP recommends to use MACROS only in EXCEPTIONAL cases.


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>