02-11-2007 4:48 AM
Hi all,
how to Filter and consolidate data in internal table as below?
input internal table:
Material batch quantity
mat1 batch1 500
mat1 batch1 200
mat1 batch2 600
mat1 batch2 300
mat2 batch3 500
mat2 batch3 200
mat2 batch4 600
mat2 batch4 300
Desired output:
mat1 <b>batch1</b> <b>700</b>
mat1 <b>batch2</b> <b>900</b>
mat2 <b>batch3</b> <b>700</b>
mat2 <b>batch4</b> <b>900</b>
how can this be achieved?
thanks,
Subba
02-12-2007 4:50 AM
take a table like itab like itab1.
loop at itab.
read table itab1 with key matnr = itab-matnr charg = itab-charg.
if sy-subrc = 0.
itab1-value = itab-value + itab1-value.
modify itab1 index sy-tabix.
else.
move-corresponding itab to itab1.
append itab1.
endif.
clear : itab,itab1.
endloop.
now your itab1 is containing the value.
NB here both the table are with header line .
regards
shiba dutta
02-11-2007 2:21 PM
Hi krishna,
U can use <b>collect</b> stmt in this case.
Try that one.
Regards....
Arun.
02-11-2007 8:53 PM
Hi Subba,
Declar an internal table same as first one in which you have data. Now do the loop at first internal table & assign the values to wark area of 2nd internal table. then use COLLECT WA to ITAB2 statement instead of APPEND.
Ashven.
02-12-2007 3:37 AM
02-12-2007 4:50 AM
take a table like itab like itab1.
loop at itab.
read table itab1 with key matnr = itab-matnr charg = itab-charg.
if sy-subrc = 0.
itab1-value = itab-value + itab1-value.
modify itab1 index sy-tabix.
else.
move-corresponding itab to itab1.
append itab1.
endif.
clear : itab,itab1.
endloop.
now your itab1 is containing the value.
NB here both the table are with header line .
regards
shiba dutta
02-12-2007 2:28 PM
Hi Subba,
Do like this:
Suppose you have internal table like this:
DATA: begin of itab occurs 100,
matnr type matnr,
charg type charg,
price type netwr,
end of itab.
Now declare another intenal table like itab.
DATA: itab2 like table of itab occurs 0 with header line.
For desired output:
LOOP at itab.
itab2-matnr = itab-matnr.
itab2-charg = itab-charg.
itab2-price = itab-price.
COLLECT iab2.
ENDLOOP.
After the endloop itab2 will be containg the desired output.
Reward points if helpful answer.
Ashvender
06-19-2007 3:35 AM