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: 

Internal Table (Consolidation)

Former Member
0 Kudos

Hi Friends...

I got this problem. Imagine I have this Internal Table.

Table1

mandt datum repid dumpid

200 26052008 Ztest2 errorA

200 26052008 Ztest1 errorA

200 26052008 Ztest1 errorA

200 26052008 Ztest2 errorA

200 26052008 Ztest2 errorA

200 26052008 Ztest2 errorA

200 26052008 Ztest1 errorB

200 26052008 Ztest1 errorA

And I Need to "consolidated" this table and generate another table like this.

Table2

mandt datum repid dumpid QTD

200 26052008 Ztest1 errorA 3

200 26052008 Ztest1 errorB 1

200 26052008 Ztest2 errorA 4

My first step was to sort the main table by repid and dumpid.

mandt datum repid dumpid

200 26052008 Ztest1 errorA

200 26052008 Ztest1 errorA

200 26052008 Ztest1 errorA

200 26052008 Ztest1 errorB

200 26052008 Ztest2 errorA

200 26052008 Ztest2 errorA

200 26052008 Ztest2 errorA

200 26052008 Ztest2 errorA

But Im having problem with the loop. (using at end of).

Data: l_count type i.

loop at table1.

at new repid.

clear l_cont.

endat.

l_count = l_count + 1.

at end of dumpid.

table2-mandt = table1-mandt.

table2-datum = table1-datum.

table2-repid = table1-repid.

table2-dumpid = table1-dumpid.

table2-qtd = l_count.

append table2.

endat.

endloop.

But my l_count always get "cleared", because always enter at "at new repid". Am i forgeting something?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Yeah... its working.... now my table2 have only one registry of each. But my qtd remains 1 for all.

trying

7 REPLIES 7

Former Member
0 Kudos

Hello,

Try this:


SORT table1 BY mandt datum repid dumpid.

LOOP AT table1.
  MOVE-CORRESPONDING table1 TO table2.
  table2-qtd = 1.
  COLLECT table2.
ENDLOOP.

Regards.

naimesh_patel
Active Contributor
0 Kudos

Instead of your LOOP, use this loop with COLLECT statement.


loop at table1.
table2-mandt = table1-mandt.
table2-datum = table1-datum.
table2-repid = table1-repid.
table2-dumpid = table1-dumpid.
table2-qtd = 1.
collect table2.
clear   table2.
endloop.

Regards,

Naimeh Patel

Former Member
0 Kudos

Trying solutions provided.

Well, I think my dificult will be because those tables are differente then one another. Table 1 have a lot of others fields I dont need at table 2.

trying

Former Member
0 Kudos

Still not working... Maybe It is need to declare some fields of my internal table as unique key to collect work properly?

trying

Former Member
0 Kudos

Yeah... its working.... now my table2 have only one registry of each. But my qtd remains 1 for all.

trying

0 Kudos

QTD field must be type I, P or F.

Regards,

Naimesh Patel

Former Member
0 Kudos

Return to use standard table without unique key and it worked fine. -

Wow. Thank you.

rewarding