2006 May 11 5:51 PM
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 .
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 .
2006 May 11 5:53 PM
hi Sateesh,
Fetch the data from the database table to internal tables and use <b>inner join</b> statement...
Regards,
Santosh
2006 May 11 5:53 PM
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
2006 May 11 5:57 PM
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
2006 May 11 6:11 PM
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
2010 Jul 01 3:10 PM