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: 

Inner Join issue

Former Member
0 Kudos

Hi everybody,

Can we inner join 4 tables at a time.

i have used the following code,

select amatnr amtart bwerks blgort cabcin diblnr

into table rep_data from

mara as a inner join

mard as b on amatnr = bmatnr inner join

marc as c on cmatnr = amatnr inner join

iseg as d on dmatnr = amatnr

where a~matnr in s_matnr

and a~mtart in s_mtart

and b~werks in s_werks

and b~lgort in s_lgort

and c~abcin in s_abcin.

Is It correct, or changes to be done or

iS there any code to do this.

Thanks,

Rajesh.

4 REPLIES 4

anversha_s
Active Contributor
0 Kudos

hi,

chnage ur code like blow,

look the bold part

select amatnr amtart bwerks blgort cabcin diblnr

into table rep_data

from

mara as a

inner join

mard as b

on amatnr = bmatnr

inner join

marc as c

on <b>amatnr = cmatnr</b>

inner join

iseg as d on <b>amatnr = dmatnr</b>

where a~matnr in s_matnr

and a~mtart in s_mtart

and b~werks in s_werks

and b~lgort in s_lgort

and c~abcin in s_abcin.

rgds

anver

mark hlpful answers

former_member186741
Active Contributor
0 Kudos

for efficiency you have to join at each level and work down the hierarchy mara->marc->mard:

select maramatnr maramtart marcwerks mardlgort marcabcin diblnr

into table rep_data from

mara inner join

marc on marcmatnr = maramatnr

inner join

mard on mardmatnr = amatnr

and mardwerks = marcwerks

inner join

iseg as d on dmatnr = amatnr

where mara~matnr in s_matnr

and mara~mtart in s_mtart

and marc~werks in s_werks

and marc~abcin in s_abcin

and mard~lgort in s_lgort

.

Former Member
0 Kudos

u can use any number of tables but should have unique key.I have use 5 tables.

also give as many condns as possible.

Former Member
0 Kudos

Yes, you can join 4 tables but in your case would advice to leave out ISEG, since you are trying to link with a non-primary key...the better soln would be to get the information for material from mara/marc/mard into an internal table.

Later use the same with FOR ALL ENTRIES to fetch data from ISEG alongwith Material/Plant and Storage location information.

Hope the above helps !!!