Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT FROM multiple tables INTO one internal Table

Tags:

select

abap

My db tables:

db_1
db_2
db_3

My internal table:

it_comb

it_comb has a structure with some fields from db_1, db_2, db_3.

All db tables have different structures.

I want to select everything from db_1, db_2, db_3 into the correct fields of it_comb with a where condition.

I would like to do something like this: (This doesn't work)

SELECT * From db_1, db_2, db_3 into CORRESPONDING FIELDS OF TABLE it_comb WHERE db_1-MATNR LIKE db_2-MATNR AND db_1-MATNR LIKE db_3-MATNR.

Obviously, this doesn't work because I can't use ',' like that. How do I write this in ABAP? So that it_comb is filled with data from db_1, db_2 and db_3.

Another problem is that every time I select something into it_comb, my previous data gets overwritten.

Code example would be appreciated for ABAP-Beginner.

like image 524
Kevin Mueller Avatar asked Jul 04 '26 02:07

Kevin Mueller


1 Answers

You can use inner join -

SELECT * APPENDING CORRESPONDING FIELDS OF TABLE it_comb
FROM db_1 AS a
INNER JOIN db_2 AS b
ON a~matnr = b~matnr
INNER JOIN db_3 AS c
ON a~matnr = c~matnr
WHERE (Your any other condition).

APPENDING won't overwrite the previous record from internal table it_comb.

Warning: Use APPENDING if internal table is TYPE STANDARD otherwise you'll get dump. Also check the SELECT - JOIN documentaion

like image 96
divScorp Avatar answered Jul 09 '26 01:07

divScorp