‎2006 Jun 26 5:50 PM
I have an itab with vbeln matnr netwr edatu fields. I am supposed to display the output containing only matnr and netwr values.
These vbeln may contain same or different matnr. So first I am sorting by matnr. When matnr are same, I am supposed to add netwr values.
I tried using 'collect' keyword like this:
Loop at itab.
collect itab.
endloop.
It's giving a small problem.For ex, when there is a single entry in tab, it adds the netwr values from the header to that entry again thus resulting in summing up single record.
Can you please suggest a correction/ new code here?
Thanks.
‎2006 Jun 26 5:55 PM
When collecting you need to COLLECT into another internal table. You want to collect by MATNR, so that needs to be one field(in this case, its the only field), and NETWR is the field that we are collecting. So you can do this.
report zrich_0001.
data: begin of itab occurs 0,
vbeln type vbak-vbeln,
matnr type vbap-matnr,
netwr type vbap-netwr,
edatu type vbep-edatu,
end of itab.
<b>data: begin of itab2 occurs 0,
matnr type vbap-matnr,
netwr type vbap-netwr,
end of itab2.</b>
loop at itab.
<b> move-corresponding itab to itab2.
collect itab2.</b>
endloop.
Regards,
Rich Heilman
‎2006 Jun 26 5:55 PM
When collecting you need to COLLECT into another internal table. You want to collect by MATNR, so that needs to be one field(in this case, its the only field), and NETWR is the field that we are collecting. So you can do this.
report zrich_0001.
data: begin of itab occurs 0,
vbeln type vbak-vbeln,
matnr type vbap-matnr,
netwr type vbap-netwr,
edatu type vbep-edatu,
end of itab.
<b>data: begin of itab2 occurs 0,
matnr type vbap-matnr,
netwr type vbap-netwr,
end of itab2.</b>
loop at itab.
<b> move-corresponding itab to itab2.
collect itab2.</b>
endloop.
Regards,
Rich Heilman
‎2006 Jun 26 5:55 PM
hi nuren,
try this..
Loop at itab.
collect itab.
append itab.
clear itab.
endloop.
‎2006 Jun 26 5:55 PM
hi Nuren,
Use Refresh keyword or clear statement before you sort or after collecting the values to an internal table...
Regards,
Santosh
‎2006 Jun 26 6:00 PM
HI Nuren,
After you use collect.
Clear the internal table.
Regards,
Laxmi.
‎2006 Jun 26 6:04 PM
Hi Nuren,
Try with the code.
DATA V_NETWR TYPE VBAP-NETWR.
DATA: BEGIN OF ITAB2 OCCURS 0,
MATNR TYPE VBAP-MATNR,
NETWR TYPE VBAP-NETWR,
END OF ITAB2.
SORT ITAB BY MATNR.
LOOP AT ITAB INTO WA.
AT NEW MATNR.
CLEAR V_NETWR.
READ TABLE ITAB INDEX SY-TABIX.
V_NETWR = V_NETWR + WA-NETWR.
CONTINUE.
ENDAT.
V_NETWR = V_NETWR + WA-NETWR.
AT END OF MATNR.
READ TABLE ITAB INDEX SY-TABIX.
ITAB2-MATNR = WA-MATNR.
ITAB2-NETWR = V_NETWR.
APPEND ITAB2.
CLEAR ITAB2.
ENDAT.
ENDLOOP.
Thanks,
Vinay