2010 Apr 13 8:41 AM
hi gurus,
My internal table contain combination of ITEM, MATNR AND VAT data,
So i want total of vat for each unique combination of ITEM and MATNR together.
how it is possible please help me on this.
thanx,
manish.
2010 Apr 13 9:10 AM
Hi Manish,
Is it possible to maintain different number of MATNR for same Items?
anyway You may use 'on change of' Keyword for your scenario.
read table it_table index 1 into wa.
temp_item = wa-item.
loop at it_table into wa.
on change of wa-MATNR.
if wa-item = temp_item.
vat_sum = wa-vat + vat_sum.
add 1 to count.
elseif count = 1. " if Unique MATNR exist
clear: vat_sum,count.
temp_item = wa-item.
add 1 to count.
else." if multiple MATNR exist
clear: vat_sum,count.
temp_item = wa-item.
add 1 to count.
endif.
endon.
endloop.
hi gurus,
My internal table contain combination of ITEM, MATNR AND VAT data,
So i want total of vat for each unique combination of ITEM and MATNR together.
how it is possible please help me on this.
thanx,
manish.
2010 Apr 13 8:47 AM
Did you try it out yourself before posting here? If so, kindly show us what you have tried and where you got stuck.
2010 Apr 13 8:56 AM
2010 Apr 13 9:02 AM
HI,
Please perform the following steps.
1. sort your internal table on VAT, ITEM, MATNR and use the following logic.
loop at itab into wa.
.....calculate sum
sum = sum + VAT
on change of vat.
..............here clear the counter sum
endon.
endloop.
Alternatively you can use an ALV to display results. There you can display the subtotal as well
Hope it helps,
Raj
2010 Apr 13 9:10 AM
Hi Manish,
Is it possible to maintain different number of MATNR for same Items?
anyway You may use 'on change of' Keyword for your scenario.
read table it_table index 1 into wa.
temp_item = wa-item.
loop at it_table into wa.
on change of wa-MATNR.
if wa-item = temp_item.
vat_sum = wa-vat + vat_sum.
add 1 to count.
elseif count = 1. " if Unique MATNR exist
clear: vat_sum,count.
temp_item = wa-item.
add 1 to count.
else." if multiple MATNR exist
clear: vat_sum,count.
temp_item = wa-item.
add 1 to count.
endif.
endon.
endloop.
2010 Apr 13 10:29 AM
2010 Apr 13 9:20 AM
Hi Manish,
You can use collect statement.
itab contains item , matnr, vat.
Loop at itab .
itab1-item = itab-item.
itab1-matnr = itab-matnr.
itab1-vat = itab-vat.
collect itab1.
endloop.
Regards
Nandan
2010 Apr 13 9:31 AM
Hi Manish,
If you are having just those 3 fields in your internal table. No need of AT keyword, instead use COLLECT.
Just go thorugh the below code.
TYPES: BEGIN OF ttab,
item(4) TYPE c,
matnr TYPE matnr,
vat TYPE i,
END OF ttab.
DATA:
itab TYPE TABLE OF ttab,
wa TYPE ttab,
temp_wa TYPE ttab,
newtab TYPE TABLE OF ttab.
* Appending value to the internal table.
wa-item = '0001'.wa-matnr = '123456'.wa-vat = 10.
APPEND wa TO itab.
wa-item = '0001'.wa-matnr = '123456'.wa-vat = 10.
APPEND wa TO itab.
wa-item = '0002'.wa-matnr = '987654'.wa-vat = 25.
APPEND wa TO itab.
wa-item = '0002'.wa-matnr = '987654'.wa-vat = 25.
APPEND wa TO itab.
wa-item = '0003'.wa-matnr = '332211'.wa-vat = 30.
APPEND wa TO itab.
wa-item = '0003'.wa-matnr = '332211'.wa-vat = 30.
APPEND wa TO itab.
* Sorting the internal table.
SORT itab BY item matnr.
LOOP AT itab into wa.
* Here collect will add the records of same key or it will append a new record.
COLLECT wa INTO newtab.
ENDLOOP.
* To display the result
LOOP AT newtab INTO wa.
WRITE: / wa-item,wa-matnr,wa-vat.
ENDLOOP.
Hope this may help you.
Regards,
Smart Varghese
2010 Apr 13 10:25 AM
IT WILL ADD UP COMMON ROWS
but i want addition of rows having unique item and matnr