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 we join two internal table

Former Member
0 Kudos

suppose both table have entries.

iist itab has 3 column ,2 contain 5 column

2 column are common

i want to pick up one column that is not prasent in second itab and 2 columns from 2nd itab which are not present in ist itab

and two column athat are common i can also pick with these column.

now i have 5 columns based on this i want to fatch data form database how

suppose in 2nd itab have multiple enteries corresponding one record in 1st itab

how we procedd we cant use read becuase it always pick single record.

5 REPLIES 5

former_member226234
Contributor
0 Kudos

Hi,

You cannot use two internal tables in a select query. Instead move the records from the two tables into a single table and use this table in selecting data from the DB.

Hope i got your query right!

Cheers,

Former Member
0 Kudos

Hi

You can use APPEND LINES OF itab1 TO itab2, when there is no condition and the structure of the 2 internal tables are the same.

If you have to join 2 internal tables upon some condition, then Loop is necessary.without looping it is not possible.

former_member194613
Active Contributor
0 Kudos

you have to program a nested loop


sort itab by ....
loop at itab1 into wa1.
  read itab2 into wa2
          with key ...binary search
    wa3-col1 = ...
    ....
    wa3-col5 =
    append wa3 to itab3.
endloop

The new table itab3 is the join.

Siegfried

0 Kudos

sort itab by ....

loop at itab1 into wa1.

read itab2 into wa2

with key ...binary search

wa3-col1 = ...

....

wa3-col5 =

append wa3 to itab3.

endloop

in your answer above where is loop on itab3 is it correct

former_member194613
Active Contributor
0 Kudos

sort itab2 by ....
loop at itab1 into wa1.
  read itab2 into wa2
          with key ...  binary search
    if ( sy-subrc eq 0 ).   
       wa3-col1 = ...
       ....
        wa3-col5 =
       append wa3 to itab3.
   endif. 
endloop.

the resulting table itab3 in something like an inner join of itab1 and itab2.

Outer joins would mean that itab3 has also lines which are only in one internal table and not in both. They are a bit more complicated, but I think you need the

inner join-type.

There is no loop an itab3, it is built by the appends.

Siegfried