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: 

Join 2 internal tables

Former Member
0 Kudos

Hello,

i have to join the whole content of a table with the content of a aggregated table. i "moved" the content of the 2 dictionary tables into 2 internal tables and i want to join these 2 internal tables now.

first of all, is it generally possible to join 2 internal tables, for example with a read or loop statement?!

at second, i know how i would solve the problem in oracle 10g, but it looks like that open-sql supports not the same features like orcale. knows anyone of you how i can rebuild the following oracle statement in abap.

#####

select a.id, a.col1, b.col2

from table_a as a, (select id, sum(col2) as col2 from table_c group by id) as b where a.id = b.id order by 1

#####

thx

5 REPLIES 5

Former Member
0 Kudos

It's best to "join" two internal tables by looping through the first and reading the second using a binary search.

Rob

Clemenss
Active Contributor
0 Kudos

Hello Markus

ABAP open sql ahould be something like

select aid acol1 sum( b~col2 )

from table_a as a

join table_c as b

on aid = bid

group by b~id

not sure abour the order by; don't know oracle syntax exactly.

Try!

Regards,

Clemens

Former Member
0 Kudos

A good programming practice is use a join query as stated earlier.

Else you can use field symbols to define the structure. Then assign the data to them. This is useful if you know dynamic programming.

Regards,

Sandeep Josyula

former_member181962
Active Contributor
0 Kudos

Hi Markus,

Say we have internal tables itab1 and itab2.

The link between these two tables is say, field1.

Then you should do something like this:

loop at itab1.

read table itab2 with key field1 = itab1-field1.

if sy-subrc = 0.

move-correspoding itab1 to it_final.

move-correspoding itab2 to it_final.

append it_final.

clear it_final.

endif.

endloop.

Regards,

Ravi

Former Member
0 Kudos

The below should give you the result

SELECT AID ACOL1 sum(B~COL2) INTO TABLE ITAB

FROM TABLE_A AS A INNER JOIN TABLE_B AS B

ON AID = BID

GROUP BY AID ACOL1

ORDER BY A~ID.