Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Macros

Former Member
1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
647

Hi,

As programs grow larger and larger, it becomes more difficult for programmers to enhance and debug source code. Luckily, computer languages make developers' lives easier by offering various modularization methods, making program code meaningful and easily understandable.

ABAP, SAP's programming language, is no exception. It leverages various modularization options, each having its own strengths and weaknesses. These options may have local access from a particular program—such as form routines and macros—or they may have global access, such as function modules or include programs.

Although a comprehensive discussion of all the modularization techniques available in ABAP is beyond the scope of this article, we can look at one option—macros—and consider some situations where they work better than other options.

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db972835c111d1829f0000e829fbfe/content.htm

And here is a sample code which explains Macros:

*DATA: result TYPE i,

*n1 TYPE i VALUE 5,

*n2 TYPE i VALUE 6.

*

    • This is macro definition.

*DEFINE operation.

*result = &1 &2 &3. "&1 &2 &3 are place holders

*output &1 &2 &3 result. " Calling the macro output

*END-OF-DEFINITION.

*

    • This is another macro (output) definition

*DEFINE output.

*write: / 'The result of &1 &2 &3 is', &4. " 4 place holders passed to

  • " this macro

  • " Here &4 is the place holder

  • " for result

*END-OF-DEFINITION.

*

*

    • Calling the macro operation 3 times with three different

    • operation( addition, power, subtraction ).

*

  • operation 4 + 3. "Here &1 place holder for 4

  • " &2 place holder for +

  • " &3 place holder for 3

  • operation 2 ** 7. "Here &1 place holder for 2

  • " &2 place holder for **

  • " &3 place holder for 7

  • operation n2 - n1. "Here &1 place holder for n2

  • " &2 place holder for -

  • " &3 place holder for n1

Hope this info helps.

regards,

kumar.

4 REPLIES 4
Read only

Peter_Inotai
Active Contributor
0 Likes
647

Very old way of implementing subroutines, they shouldn't be used. Check DEFINE macro. statement documentation via F1 help.

Peter

Read only

Former Member
0 Likes
647

Macros are like subroutines..but not used i guess

DEFINE INCREMENT.

ADD 1 TO &1.

END-OF-DEFINITION.

DATA: NUMBER TYPE I VALUE 1.

...

INCREMENT NUMBER.

1. As a rule, you should use subroutines (FORM, FUNCTION)

instead of macros. This is because subroutines - unlike

macros - are supported by all of the ABAP Workbench tools

(debugging, runtime analysis, runtime error handling, ...).

2. You cannot define a macro within a macro using the DEFINE

statement.

3. You cannot use an ABAP keyword as a macro name.

4. The validity of a macro definition is determined by its

position in the source code. You can use a given macro in

any line of code following its definition. There is no

distinction between global and local macros. For example,

the fact that a macro is defined within a subroutine has no

effect on its validity.

5. If you redefine a macro, that is, assign a new meaning to

an existing name, the new meaning takes effect from the

position in the program where the macro was redefined.

Read only

Former Member
0 Likes
647

Hi,

Look at the below link

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db972835c111d1829f0000e829fbfe/content.htm

Look at the below link for Program which are developed using the Macros

http://www.sap-img.com/ab022.htm

Regards

Sudheer

Read only

Former Member
0 Likes
648

Hi,

As programs grow larger and larger, it becomes more difficult for programmers to enhance and debug source code. Luckily, computer languages make developers' lives easier by offering various modularization methods, making program code meaningful and easily understandable.

ABAP, SAP's programming language, is no exception. It leverages various modularization options, each having its own strengths and weaknesses. These options may have local access from a particular program—such as form routines and macros—or they may have global access, such as function modules or include programs.

Although a comprehensive discussion of all the modularization techniques available in ABAP is beyond the scope of this article, we can look at one option—macros—and consider some situations where they work better than other options.

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db972835c111d1829f0000e829fbfe/content.htm

And here is a sample code which explains Macros:

*DATA: result TYPE i,

*n1 TYPE i VALUE 5,

*n2 TYPE i VALUE 6.

*

    • This is macro definition.

*DEFINE operation.

*result = &1 &2 &3. "&1 &2 &3 are place holders

*output &1 &2 &3 result. " Calling the macro output

*END-OF-DEFINITION.

*

    • This is another macro (output) definition

*DEFINE output.

*write: / 'The result of &1 &2 &3 is', &4. " 4 place holders passed to

  • " this macro

  • " Here &4 is the place holder

  • " for result

*END-OF-DEFINITION.

*

*

    • Calling the macro operation 3 times with three different

    • operation( addition, power, subtraction ).

*

  • operation 4 + 3. "Here &1 place holder for 4

  • " &2 place holder for +

  • " &3 place holder for 3

  • operation 2 ** 7. "Here &1 place holder for 2

  • " &2 place holder for **

  • " &3 place holder for 7

  • operation n2 - n1. "Here &1 place holder for n2

  • " &2 place holder for -

  • " &3 place holder for n1

Hope this info helps.

regards,

kumar.