Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Thursday, February 21, 2008

How to use macros in sap

First : DO NOT use macros in a new program, there is a lot of better way to do it.

Some people come to my desk and tell me they found a "magic" function which the code behind is invisible and it's impossible to trace this function. In some old programs, you can see a strange call to what it look like a function but it's not, it's a macro.

The macros are stored in table TRMAC.

One of the most used macros is "break". To put a break-point in your code that will break only for your user name, you probably use "break my_user_name". This is not part of the ABAP language despite what a lot of people think; it's a macro. If you have a look in table TRMAC, you will see :

BREAK 000 * USER specific BREAK-POINT

BREAK 001 if sy-uname = '&1'

BREAK 002 break-point

BREAK 003 endif

Here is how to create a simple macro, for the sake of understanding what old programs do. Again, do not

create new macros unless you absolutely must.

REPORT zdany_macro.

*Macro definition
DEFINE ZMULTIPLY.
  MULTIPLY &1 BY &2.
END-OF-DEFINITION.
     
DATA: number1 TYPE i VALUE 2,
      number2 TYPE i VALUE 5.
     
* calling the macro, no easy way of knowing this is a macro
ZMULTIPLY number1 number2.
     
WRITE number1.

First : DO NOT use macros in a new program, there is a lot of better way to do it.

Some people come to my desk and tell me they found a "magic" function which the code behind is invisible and it's impossible to trace this function. In some old programs, you can see a strange call to what it look like a function but it's not, it's a macro.

The macros are stored in table TRMAC.

One of the most used macros is "break". To put a break-point in your code that will break only for your user name, you probably use "break my_user_name". This is not part of the ABAP language despite what a lot of people think; it's a macro. If you have a look in table TRMAC, you will see :

BREAK 000 * USER specific BREAK-POINT

BREAK 001 if sy-uname = '&1'

BREAK 002 break-point

BREAK 003 endif

Here is how to create a simple macro, for the sake of understanding what old programs do. Again, do not

create new macros unless you absolutely must.

REPORT zdany_macro.

*Macro definition
DEFINE ZMULTIPLY.
  MULTIPLY &1 BY &2.
END-OF-DEFINITION.
     
DATA: number1 TYPE i VALUE 2,
      number2 TYPE i VALUE 5.
     
* calling the macro, no easy way of knowing this is a macro
ZMULTIPLY number1 number2.
     
WRITE number1.

No comments:

Post a Comment

Content

Recent Topics