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
0 Likes
586

Hi

I am srikanth and have a query on following:-

1 Wat is macro ?

how it works ?

send me with small example

Regards

Srikanth

4 REPLIES 4
Read only

Former Member
0 Likes
507

Hi,

The basic syntax of macros is as follows:

DEFINE macro_name. "Macro Definition

……………. Statements

……………. Statements

…………………

END-OF-DEFINITION. "Macro Definition

macro_name par1 par2 …par9. "Macro call -parameters separated by spaces

Within the DEFINE... and END-OF-DEFINITION lies the body of the macro—the statements that you wish to be executed each time the macro is called. These statements may be any valid ABAP statements, such as WRITE, CLEAR, FORM calls, or database statements such as SELECT or UPDATE.

To familiarize yourself with the working of macros, it's necessary to take a close look at exactly what happens when an ABAP program containing a macro call is generated. Consider Listing A.

All ABAP programs must be generated before they can be executed. At the time of program generation, the system supplants each macro call, as shown in Listing A, with the statement(s) placed between the macro definition. Furthermore, the parameters passed at the time of macro calling are copied in place of the any placeholders (numbered &1, &2 …&9) found in the body of the macro definition. The system simply ignores the presence of the macros during the execution of the program—that is, all statements are executed as a single block of code:

write : int1.

write : int2.

write : int3.

Other than readability and meaningfulness, macros also offer performance advantages. For testing purposes, I wrote a macro that incremented the value of a variable by 1 and called the macro N times via a DO loop, as shown here:

DEFINE INCREMENT.

ADD 1 TO &1.

END-OF-DEFINITION.

DO N TIMES.

INCREMENT VAR1.

ENDDO.

Read only

Former Member
0 Likes
507

Hi,

Kindly check the program "DEMO_MOD_TECH_MACROS" in se38 to know more about Macros.

Macros are one way of modurlization of your code.

Cheers

VJ

Read only

Former Member
0 Likes
507

Hi ,

plz find another small example..

data: v_p1 type i value 30.

define psl.

write: &1.

end-of-definition.

psl v_p1.

psl: name of macro.

Read only

0 Likes
507

Hi,

macros have been introduced to reduce the writing efforts done when a program is developed. They are resolved and translated into program code at compile/generation time. That means they will not change anything about program performance.

The disadvantage of macros is that you can not trace the execution in DEBUG mode.

For this reason I never use macros in my programs. But if you do not want that other people understand your programming logic then it is a god idea to put the logic into macros -:)

An module that can be called within an ABAP program.

Use

Like subprograms and function modules, macro modules are a means of presenting programs in modular form. Macro modules (macros) are used often in the Human Resources application component (HR).

Defining and Calling Modules

Two options are provided:

  • Macros can be defined in reports or includes using the ABAP command DEFINE. A macro can be used within a report or within an include. If a macro is used in a report, and the macro is defined in an include with the DEFINE command, the include must be integrated.

Note

Macros have the following advantages:

If a macro is changed, each report using this macro is automatically regenerated when it is executed.

  • Macros can also be defined as RMAC macros. The source code of these modules is stored in the function section of the control table TRMAC (Macros in ABAP Programs). The coding is grouped under a specific name in the table key.

According to conventions, the first two letters of the name must stand for the application. The rest of the name is freely definable.

Recommendation

Customer-specific RMAC modules should begin with a special character.

The macros defined in the control table TRMAC can be used by all reports.

Caution

When you change a RMAC macro in the table TRMAC, the reports that use this macro are not regenerated automatically. You must regenerate them manually.

Regards,

Clemens