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

problem related to AT statement

Former Member
0 Likes
1,092

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,049

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.

8 REPLIES 8
Read only

Former Member
0 Likes
1,049

Did you try it out yourself before posting here? If so, kindly show us what you have tried and where you got stuck.

Read only

0 Likes
1,049

i dont know how to start to get the value.

Read only

Former Member
0 Likes
1,049

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

Read only

Former Member
0 Likes
1,050

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.

Read only

0 Likes
1,049

it is showing only value of first unique row

Read only

SrihariNerella
Participant
0 Likes
1,049

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

Read only

Former Member
0 Likes
1,049

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

Read only

0 Likes
1,049

IT WILL ADD UP COMMON ROWS

but i want addition of rows having unique item and matnr