Application Development and Automation 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: 
Read only

can we join two internal tables

Former Member
0 Likes
2,403

Hi to all,

i want take data from one database(db) table into internal table from this we want to retrieve data from other db table and put this data into another internal table .provided that two db tables are depends on foreign key relations .

5 REPLIES 5
Read only

Former Member
0 Likes
1,239

hi Sateesh,

Fetch the data from the database table to internal tables and use <b>inner join</b> statement...

Regards,

Santosh

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,239

You can do this a number of ways. You can use an inner join in your select statement and put the required data into an internal table or you can do two selects from the db and loop at the first itab, then loop at the second where the keys match and put the required data into a third internal table.

Here is an example of using an inner joine to get data from db tables into one internal table.

report zrich_0001.

data: begin of ima occurs 0,
      matnr type mara-matnr,
      mtart type mara-mtart,
      werks type marc-werks,
      dispo type marc-werks,
      end  of ima.

select-options: s_matnr for ima-matnr.


select mara~matnr mara~mtart marc~werks marc~dispo
       into table ima
             from mara
                 inner join marc
                     on mara~matnr = marc~matnr
                             where mara~matnr in s_matnr.
loop at ima.

  write:/ ima-matnr, ima-mtart, ima-werks, ima-dispo.
endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,239

Hi,

Try this.

SELECT * FROM TABLE1 INTO ITAB1.

IF NOT ITAB1[] IS INITIAL.

SELECT * FROM TABLE2 INTO ITAB2

FOR ALL ENTRIES IN ITAB1

WHERE COLUMN = ITAB1-COLUMN.

Now,

LOOP AT ITAB1.

LOOP AT ITAB2 WHERE COLUMN = ITAB1-COLUMN.

FILL THE THIRD TAB.

ENDLOOP.

ENDLOOP.

Regards,

Ravi

Note : Please mark the helpful answers

Regards,

Ravi

Read only

Former Member
0 Likes
1,239

Sateesh,

Use left outer join which will select all data from table1 and matching records from table2... Code is as follows :

Select af1 af2 af3 bb1 b~b2

from tabel1 as a

left join table2 as b

on akey1 = bkey1.

OR you can use Inner join if you want records which are present in both tables as follows.

Select af1 af2 af3 bb1 b~b2

from tabel1 as a

Inner join table2 as b

on akey1 = bkey1.

This way you can avoid two select statement.

Cheers,

Nilesh

Message was edited by: Nilesh Kshirsagar

Read only

Former Member
0 Likes
1,239

Thanks for the useful answers