2013 Jul 02 9:08 AM
Can someone explain this what exactly this piece of code is coding. i am not that much clear with macros.
DEFINE build_select.
if not &1[] is initial.
lt_select-tag = '&2'.
loop at &1.
move-corresponding &1 to lt_select.
collect lt_select.
endloop.
endif.
END-OF-DEFINITION.
Thanks
Pavan.N
2013 Jul 02 9:13 AM
Hi,
the code replace &1 with the first variable, &2 with the second variable ...
so you will find in other place of the code : build_select var1 var2.
the macro could not be debugged
regards
Fred
2013 Jul 02 10:34 AM
Hi,
I am not clear..
this is the code ...can u give me the better idea.
DATA: lt_display TYPE TABLE OF ZIFSSTFL WITH HEADER LINE.,
lr_kostl TYPE TABLE OF zselstr WITH HEADER LINE,
lt_select TYPE TABLE OF ztrssopt WITH HEADER LINE.
DEFINE build_select.
if not &1[] is initial.
lt_select-tag = '&2'.
loop at &1.
move-corresponding &1 to lt_select.
collect lt_select.
endloop.
endif.
END-OF-DEFINITION.
build_select lr_kostl kostl.
build_select s_pernr pernr.
thanks.
Pavan.N
2013 Jul 02 11:52 AM
Hi Pavan,
- In above code, the statement "build_select lr_kostl kostl" means you are calling above defined MACRO with statement DEFINE....END-OF-DEFINATION.
- So when the statement "build_select lr_kostl kostl" is called then at runtime, the code will replace &1 with 'lr_kostl' and &2 with 'kostl' so your code at run time will be :
build_select lr_kostl kostl.
if not lr_kostl[] is initial.
lt_select-tag = 'kostl'.
loop at lr_kostl.
move-corresponding lr_kostl to lt_select.
collect lt_select.
endloop.
endif.
And in "build_select s_pernr pernr" statement.
build_select s_pernr pernr.
if not s_pernr[] is initial.
lt_select-tag = 'pernr'.
loop at s_pernr.
move-corresponding s_pernr to lt_select.
collect lt_select.
endloop.
endif.
2013 Jul 02 9:25 AM
Hi Pavan,
See this link to learn about macros
http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db972835c111d1829f0000e829fbfe/content.htm
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.
his 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
2013 Jul 02 9:28 AM
This is how macro works.
data: begin of itab occurs 0,
col1(2),
col2(5),
col3(3),
end of itab.
define ex.
itab = &1.
end-of-definition.
start-of-selection.
ex 'Wedonotlie'.
.....
The above code will pass 'Wedonotlie' to &1 in macro ex. After assigning &1 to itab,
we will have itab-col1 = 'We', itab-col2 = 'donot' and itab-col3 = 'lie'
In your example, the code moves field values of internal table (&1) to corresponding fields of lt_select.
for all records of &1 it will assign &2 to <tag field> of lt_select . It collects the rows of lt_select as and when it is appended.
So somewhere in main program you might have statement like
build_select it_mara 'MAT'.
above will pass internal table it_mara as &1 and 'MAT' as &2 to macro build_select.
Got it ?
Regards,
Vishram
Why it is still under moderation ? Even after 3 hours ?
Message was edited by: Vishram Kendurkar Why it is stll under consideration by moderator ?
2013 Jul 02 10:35 AM
Assuming macro is called like this:
build_select var1 var2.
var1 is internal table that is being looped into.
var2 contains value for field tag of table lt_select.
Macro will populate lt_select-tag with var2.
Common fields of record var1 will be populated into var2.
And then there is a collect statement which will append or modify record of lt_select.