‎2006 Sep 22 7:24 AM
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.
‎2006 Sep 22 7:29 AM
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
‎2006 Sep 22 7:47 AM
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
.
‎2006 Sep 22 8:08 AM
u can use any number of tables but should have unique key.I have use 5 tables.
also give as many condns as possible.
‎2006 Sep 22 9:35 AM
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 !!!