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

Macro defination

Former Member
0 Likes
775

Hi Guys,

Can you please expalin me how this MACRO works.what is " check not &2 is initial" in the macro below?

DEFINE mac_error_data.

check not &2 is initial.

g_msgseq = g_msgseq + 1.

move: iest0-company to itab_error-company,

iest0-customer to itab_error-customer,

iest0-bill_no to itab_error-bill_no,

g_msgseq to itab_error-msgseq.

concatenate &1 &2 into itab_error-error_code.

append itab_error. clear itab_error.

clear: error_text.

END-OF-DEFINITION.

5 REPLIES 5
Read only

Former Member
0 Likes
703

Hi,

It's quite similar with routine if you're familiar with it.

From your sample macro, i can type this as a caller (similar with perform in routine):

mac_error_data varA varB

when come to macro definition (similar with form in routine)

&1 will change to value from varA

&2 will change to value from varB

so this syntax:

check not &2 is initial.

means: check not varA is initial.

Hope it helps,

Victor.

Read only

Sm1tje
Active Contributor
0 Likes
703

In addition to Victor, all 'variables' within marco definition are socalled placeholders.

Read only

Former Member
0 Likes
703

Macros are used whenever we want to execute a piece of code multiple time. Plese see the below example.

Defile calculate.

&3 = &2 + &1.

end of difination.

Loop at itab.

calculate itab-field1 itab-field3 itab-field3.

end loop.

The output will be

itab-field3 = itab-field2 + itab-field1.

suppose itab-field1 = 10

itab-field2 = 5.

then according to the above macro

itab-field3 = 15.

In ur case, macro is check for the second passed variable for example

DEFINE mac_error_data.

check not &2 is initial.

g_msgseq = g_msgseq + 1.

move: iest0-company to itab_error-company,

iest0-customer to itab_error-customer,

iest0-bill_no to itab_error-bill_no,

g_msgseq to itab_error-msgseq.

concatenate &1 &2 into itab_error-error_code.

append itab_error. clear itab_error.

clear: error_text.

END-OF-DEFINITION.

loop at itab.

mac_error_data itab-field1 itab-field12." Macro will be perform only if the itab-field12 is initial

endloop.

Read only

Former Member
0 Likes
703

Hi Akal,

In code you call the macro as follows:

mac_error_data VAR1 VAR2.

What macro does:


DEFINE mac_error_data.
check not &2 is initial.                                         "If VAR2 is not initital
g_msgseq = g_msgseq + 1.                                " add 1 to g_msgseq 
move: iest0-company to itab_error-company,         "itab_error-company = iest0-company
iest0-customer to itab_error-customer,                  "itab_error-customer = iest0-customer
iest0-bill_no to itab_error-bill_no,                          "itab_error-bill_no = iest0-bill_no
g_msgseq to itab_error-msgseq.                          " itab_error-msgseq = g_msgseq 
concatenate &1 &2 into itab_error-error_code.       " concatenate VAR1 and VAR2 into itab_error-error_code
append itab_error. clear itab_error.                       " fill itab_error internal table with the above header information
clear: error_text.
END-OF-DEFINITION.

George

Read only

Former Member
0 Likes
703

Hi Alka,

Chk this,

Examples of Macro

REPORT ZEX_MACRO .

* Parameter Declaration
Parameters: d_num1 type i,
            d_num2 type i.

* Data Declaration
DATA: d_res TYPE i.

* This Macro performs the operation
DEFINE operation.
  d_res = &1 &2 &3.
  doit   &1 &2 &3 d_res.
END-OF-DEFINITION.

* This Macro gives the result
DEFINE doit.
  write: / 'The result of &1 &2 &3  is', &4.
END-OF-DEFINITION.

Regards,

Nikhil.