Application Development 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: 

how to Filter and consolidate data ?

vsubbakrishna
Participant
0 Kudos
135

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos
103

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

6 REPLIES 6

Former Member
0 Kudos
103

Hi krishna,

U can use <b>collect</b> stmt in this case.

Try that one.

Regards....

Arun.

Former Member
0 Kudos
103

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.

0 Kudos
103

thanks all,

i will try and update....pls keep posted..

subba

Former Member
0 Kudos
104

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

0 Kudos
103

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

vsubbakrishna
Participant
0 Kudos
103

Answered!!