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
733

what is macro ? how it will be used in realtime and can u debug a macro

4 REPLIES 4
Read only

Former Member
0 Likes
698

Hi,

macro is just useful like subroutienes.but we can't debugg the macro.

see this simple example.

data:result(3) type n.

define addition.

result = &1 &2 &3.

write:/ 'result of &1 &2 &3 is:',result.

end-of-definition.

addition 10 + 20.

for more info see this link

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

rgds,

bharat.

Read only

Former Member
0 Likes
698

Hi,

Macros

If you want to reuse the same set of statements more than once in a program, you can include

them in a macro. For example, this can be useful for long calculations or complex WRITE

statements. You can only use a macro within the program in which it is defined, and it can only

be called in lines of the program following its definition.

The following statement block defines a macro <macro>:

DEFINE <macro>.

<statements>

END-OF-DEFINITION.

You must specify complete statements between DEFINE and END-OF-DEFINITION. These

statements can contain up to nine placeholders (&1, &2, ..., &9). You must define the macro

before the point in the program at which you want to use it.

Macros do not belong to the definition part of the program. This means that the DEFINE...ENDOF-

DEFINITION block is not interpreted before the processing blocks in the program. At the

same time, however, macros are not operational statements that are executed within a

processing block at runtime. When the program is generated, macro definitions are not taken

into account at the point at which they are defined. For this reason, they do not appear in the

overview of the structure of ABAP programs [Page 44].

A macro definition inserts a form of shortcut at any point in a program and can be used at any

subsequent point in the program. As the programmer, you must ensure that the macro

definition occurs in the program before the macro itself is used. Particular care is required if you

use both macros and include programs, since not all include programs are included in the syntax

check (exception: TOP include).

To use a macro, use the following form:

<macro> [<p1> <p2> ... <p9>].

When the program is generated, the system replaces <macro> by the defined statements and

each placeholder &i by the parameter <pi>. You can use macros within macros. However, a

macro cannot call itself.

Ex.

DATA: RESULT TYPE I,

N1 TYPE I VALUE 5,

N2 TYPE I VALUE 6.

DEFINE OPERATION.

RESULT = &1 &2 &3.

OUTPUT &1 &2 &3 RESULT.

END-OF-DEFINITION.

DEFINE OUTPUT.

WRITE: / 'The result of &1 &2 &3 is', &4.

END-OF-DEFINITION.

OPERATION 4 + 3.

OPERATION 2 ** 7.

OPERATION N2 - N1.

The produces the following output:

The result of 4 + 3 is 7

The result of 2 ** 7 is 128

The result of N2 - N1 is 1

Here, two macros, OPERATION and OUTPUT, are defined. OUTPUT is nested in

OPERATION. OPERATION is called three times with different parameters. Note how

the placeholders &1, &2, ... are replaced in the macros.

The following example shows that a macro definition only works in the program lines

following its definition. Do not copy it!

Suppose we have a program with a subroutine TEST:

PROGRAM MACRO_TEST.

...

FORM TEST.

WRITE '...'.

ENDFORM.

Suppose we then changed the program to the following:

PROGRAM MACRO_TEST.

...

FORM TEST.

DEFINE MACRO.

WRITE '...'.

ENDFORM.

END-OF-DEFINITION.

MACRO.

Inserting the macro changes nothing in the generated form of the program.

Processing blocks - here a subroutine - are always indivisible. We could also write

the program as follows:

PROGRAM MACRO_TEST.

...

DEFINE MACRO.

WRITE '...'.

ENDFORM.

END-OF-DEFINITION.

...

FORM TEST.

MACRO.

The most essential feature of a macro definition is that it should occur before the

macro is used.

Regards,

Bhaskar

Read only

Former Member
0 Likes
698

Hi,

Debugging a macro is not possible.

Regards

Bala

Read only

Former Member
0 Likes
698

Hi

gurus i am very gratefully to those who responded to my query

Regards

suresh