Skip to Content

Macro contra Form

Hello all

I just had to convert a program using macros (Define ... end-of-definition). The first thing I do in this case is always to change the macro to a subroutine - in my opinion macros has no advantage over forms, but some major disadvantages.

This make me wonder - why does SAP continue to support macros in ABAP ? - and why does some programmers continue to use macros?

Do macros in abap have any advantages or not ?

Best regards

Thomas Madsen Nielsen

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Aug 12, 2004 at 08:27 AM

    As Bogan mentioned macros may help you to benefit from the statement repeation ':' in ABAP. This repeation allows you keep the first part of command and just to enter individual tails.

    For internal table imagine the following sequence:

      insert 'Anton' into table it_Names[].
      insert 'Fred'  into table it_Names[].
      insert 'Paul'  into table it_Names[].
      insert 'Egon'  into table it_Names[].
    

    One my shorten this by use of a macro:

    define mac_Insert.
      insert &2 into table &1.
    end-of-definition.
      mac_Insert it_Names[]:    'Anton', 'Fred', 'Paul', 'Egon'.
    

    But never ever macros should contain logic, due its not possible to debug them.

    Kind Regards

    Klaus

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      The only times that I find that I have to use macros is:

      A) For the HR module (historic reasons within SAP), but these are the SAP macros.

      B) For declaring data statements. The most recent one was for a block of code to declare a selection-screen file name. Usefull if you have several input and output files.

      The inability to debug macros is a major disadvantage, when you do not know what they do!

      MattG.

  • author's profile photo
    Former Member
    Posted on Aug 12, 2004 at 08:08 AM

    The advantage in using macros, as I see it, is that the ABAP interpreter expands the code by replacing the specific areas in the macro (that you specify in the definition of it) with code specified where the macro is "called". This is helpful when the variable part is for instance a table field name, a table name etc.

    It helps in shortening the code.

    I guess you could use field symbols too, for this example.

    But maybe my example was not the best possible example.

    Add comment
    10|10000 characters needed characters exceeded