‎2009 Jun 15 8:53 AM
Hi,
I have an internal table:
material price
111111 10,00
111111 15,00
222111 12,00
222111 18,00
How to use SUM to get total price PER material? Which statement tu use?
ON CHANGE of material doesnt work..I get total price of all materials..
111111 25,00
222111 30,00
thanks..
‎2009 Jun 15 8:56 AM
‎2009 Jun 15 8:55 AM
‎2009 Jun 15 8:56 AM
‎2009 Jun 15 9:01 AM
U can also use at end statement to get the sum per material.
‎2009 Jun 15 9:05 AM
Hi,
Use AT NEW.
ON CHNAGE of is obsolute in ECC.
Regards,
Surendar Reddy.
‎2009 Jun 15 9:12 AM
check this
loop at itab.
at new matnr.
sum.
write itab-price.
skip1.
endat.
‎2009 Jun 15 9:21 AM
Hi,
You can also use LOOP AT with COLLECT statement.
Regards
Karthik D
‎2009 Jun 15 9:24 AM
Hi,
Thanks all!
AT NEW won't work if MATERIAL isn't the first kolumn??
pos material price
Is there other solution?
tnx!
‎2009 Jun 15 9:29 AM
u can make it in the first column and try if your not using any control break statement else where.
or.
loop at itab.
it1-matnr = itab-matnr.
it1-price = itab-price.
collect it1.
endloop.
‎2009 Jun 15 9:44 AM
Did you sort the internal table before using Control break statement?
Sort itab by matnr. -
> Add this statement
Loop at itab.
At new matnr.
Sum.
Endat.
Endloop.
‎2009 Jun 15 9:46 AM
‎2009 Jun 15 9:50 AM
AT NEW won't work if MATERIAL isn't the first kolumn??
Have you tried using at new itab-matnr.
‎2009 Jun 15 9:57 AM
Yes, getting error: no component exists with the name itab-matnr
‎2009 Jun 15 9:59 AM
Example:
REPORT zz_test_aa1.
TYPES: BEGIN OF ls_itab,
p(3),
matnr TYPE matnr,
price TYPE kbetr,
END OF ls_itab.
DATA: itab TYPE STANDARD TABLE OF ls_itab,
wtab TYPE ls_itab.
wtab-p = '10'.
wtab-matnr = '1111111111'.
wtab-price = '10.00'.
APPEND wtab TO itab.
wtab-p = '20'.
wtab-matnr = '1111111111'.
wtab-price = '12.00'.
APPEND wtab TO itab.
wtab-p = '30'.
wtab-matnr = '2211111111'.
wtab-price = '13.00'.
APPEND wtab TO itab.
wtab-p = '40'.
wtab-matnr = '2211111111'.
wtab-price = '14.00'.
APPEND wtab TO itab.
SORT itab by matnr.
LOOP AT itab INTO wtab.
ON CHANGE OF wtab-matnr.
SUM.
WRITE: wtab-matnr, wtab-price.
SKIP 1.
ENDON.
ENDLOOP.
‎2009 Jun 15 10:02 AM
Try this.
DATA:BEGIN OF itab OCCURS 0,
matnr TYPE matnr,
price TYPE wrbtr,
END OF itab.
START-OF-SELECTION.
CLEAR itab.
itab-matnr = '111111'.
itab-price = '10'.
APPEND itab.
CLEAR itab.
itab-matnr = '111111'.
itab-price = '15'.
APPEND itab.
CLEAR itab.
itab-matnr = '222111'.
itab-price = '12'.
APPEND itab.
CLEAR itab.
itab-matnr = '222111'.
itab-price = '18'.
APPEND itab.
SORT itab BY matnr.
LOOP AT itab.
AT NEW matnr.
SUM.
WRITE:/ itab-matnr,itab-price.
ENDAT.
ENDLOOP.
‎2009 Jun 15 10:03 AM
‎2009 Jun 15 10:07 AM
Info to all:
I'm printing invoice sapscript so i'm using internal table tvbdpr type vbdpr so I can't change kolumns here.
‎2009 Jun 15 10:09 AM
TYPES: BEGIN OF ls_itab,
matnr TYPE matnr,
price TYPE kbetr,
p(3), "Change it to third column from first column
END OF ls_itab.
DATA: itab TYPE STANDARD TABLE OF ls_itab,
wtab TYPE ls_itab.
wtab-p = '10'.
wtab-matnr = '1111111111'.
wtab-price = '10.00'.
APPEND wtab TO itab.
wtab-p = '20'.
wtab-matnr = '1111111111'.
wtab-price = '12.00'.
APPEND wtab TO itab.
wtab-p = '30'.
wtab-matnr = '2211111111'.
wtab-price = '13.00'.
APPEND wtab TO itab.
wtab-p = '40'.
wtab-matnr = '2211111111'.
wtab-price = '14.00'.
APPEND wtab TO itab.
SORT itab BY matnr.
LOOP AT itab INTO wtab.
AT NEW matnr. "Change it it At new
SUM.
WRITE: wtab-matnr, wtab-price.
SKIP 1.
ENDAT.
ENDLOOP.If we use At new material, if the left side columns change before material the control break statement wil be triggered.
‎2009 Jun 15 10:10 AM
i changed column position in my previous post. Okay i will try it with out changing the column position.
‎2009 Jun 15 10:13 AM
‎2009 Jun 15 10:41 AM
Hi,
Please try this...
TYPES: BEGIN OF ls_itab,
p(3),
matnr TYPE matnr,
price TYPE kbetr,
END OF ls_itab.
DATA: itab TYPE STANDARD TABLE OF ls_itab,
wtab TYPE ls_itab,
total_price TYPE kbetr ,
matnr1 TYPE matnr,
matnr2 TYPE matnr.
wtab-p = '10'.
wtab-matnr = '1111111111'.
wtab-price = '10.00'.
APPEND wtab TO itab.
wtab-p = '20'.
wtab-matnr = '1111111111'.
wtab-price = '12.00'.
APPEND wtab TO itab.
wtab-p = '30'.
wtab-matnr = '2211111111'.
wtab-price = '13.00'.
APPEND wtab TO itab.
wtab-p = '40'.
wtab-matnr = '2211111111'.
wtab-price = '14.00'.
APPEND wtab TO itab.
wtab-p = '50'.
wtab-matnr = '4411111111'.
wtab-price = '16.00'.
APPEND wtab TO itab.
SORT itab BY matnr.
LOOP AT itab INTO wtab.
matnr2 = wtab-matnr.
IF NOT matnr1 IS INITIAL.
IF matnr1 = matnr2.
total_price = total_price + wtab-price.
ELSE.
WRITE: matnr1, total_price.
CLEAR total_price.
total_price = wtab-price.
ENDIF.
ENDIF.
SKIP 1.
matnr1 = matnr2.
AT LAST.
WRITE: matnr2, total_price.
ENDAT.
ENDLOOP.
‎2009 Jun 15 10:44 AM
Hi,
as per your code: can you check with the below code..
SORT itab by matnr.
LOOP AT itab INTO wtab.
v_price = v_price+ wtab-price.
At end of Matnr
WRITE: wtab-matnr, v_price.
clear v_price.
endat.
ENDLOOP.
Edited by: chaitanya on Jun 15, 2009 3:17 PM
‎2009 Jun 15 10:00 AM
Use Collect Statement,
This is the most suited alternative .
‎2009 Jun 15 10:24 AM
hi
First thing is u have to change ur internal table starting with matnr
ex: DATA: beging of' itab,
matnr like mseg matnr,
xxxxx like mseg-xxxx,
..............................,
end of itab.
{CODE}
thn you have to sort it by MATNR(material number)
now within the loop u can used
AT END OF....... ENDAT
cheers
nawa
‎2009 Jun 15 10:38 AM
if its not in the first column u cannot use control break events.
if its sap script try to create a routine and use collect statement.
‎2009 Jun 15 10:44 AM
you have nearly 242 posts, still stuck with these sort of questions
all releavent answers are been provided .. now apply the right one and close the thread.
Such a long discussion
‎2009 Jun 15 10:53 AM
Try this.
I don't know wether it is suitable logic or not.
TYPES: BEGIN OF ls_itab,
p(3),
matnr TYPE matnr,
price TYPE kbetr,
END OF ls_itab.
DATA: itab TYPE STANDARD TABLE OF ls_itab,
wtab TYPE ls_itab.
DATA: BEGIN OF ls_itab1 OCCURS 0,
matnr TYPE matnr,
price TYPE kbetr,
END OF ls_itab1.
DATA:v_sum TYPE kbetr.
wtab-p = '10'.
wtab-matnr = '1111111111'.
wtab-price = '10.00'.
APPEND wtab TO itab.
CLEAR wtab.
wtab-p = '20'.
wtab-matnr = '1111111111'.
wtab-price = '12.00'.
APPEND wtab TO itab.
CLEAR wtab.
wtab-p = '30'.
wtab-matnr = '2211111111'.
wtab-price = '13.00'.
APPEND wtab TO itab.
CLEAR wtab.
wtab-p = '40'.
wtab-matnr = '2211111111'.
wtab-price = '14.00'.
APPEND wtab TO itab.
CLEAR wtab.
LOOP AT itab INTO wtab.
MOVE-CORRESPONDING wtab TO ls_itab1.
APPEND ls_itab1.
ENDLOOP.
SORT ls_itab1 BY matnr.
SORT itab BY matnr.
LOOP AT itab INTO wtab.
ON CHANGE OF wtab-matnr.
LOOP AT ls_itab1 WHERE matnr = wtab-matnr.
AT NEW matnr.
SUM.
v_sum = ls_itab1-price.
ENDAT.
ENDLOOP.
WRITE: wtab-matnr, v_sum.
CLEAR v_sum.
ENDON.
SKIP 1.
ENDLOOP.