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

inner join 4 tables

Shahid
Product and Topic Expert
Product and Topic Expert
0 Likes
2,337

can anyone give example how to join 4 tables?

SELECT mara~matnr werks xchar mtart matkl meins trame umlmc

INTO CORRESPONDING FIELDS OF TABLE t_mat

FROM mara INNER JOIN marc

ON maramatnr = marcmatnr

WHERE mara~matnr IN matnr

AND werks IN werks

AND mtart IN matart

AND matkl IN matkla

AND ekgrp IN ekgrup

AND mara~lvorm = lvorm.

select mblnr mjahr matnr werks

from mseg

into table it_mseg

for all entries in t_mat

where matnr = t_mat-matnr

and werks = t_mat-werks.

select mblnr mjahr budat

from mkpf

into table it_mkpf

for all entries in it_mseg

where mblnr = it_mseg-mblnr

and mjahr = it_mseg-mjahr.

i m adding additional field in the selection screen "BUDAT FROM MKPF'..

so look at the above code, how i wrote to get the details of bkpf.

so now i just want one select statement where it picks mara, marc fields along with mkpf-budat.

5 REPLIES 5
Read only

varma_narayana
Active Contributor
0 Likes
995

Hii Shahid...

Never join more than 3 tables .. Performance will be very poor.

Instead you can create separate internal tables and use FOR ALL ENTRIES..

So your code is better..

And one more thing

Avoind using

INTO CORRESPONDING FIELDS OF TABLE t_mat (this takes lot of time)

instead use

INTO TABLE t_mat .

<b>Reward if Helpful</b>

Read only

Former Member
0 Likes
995

Hi!

select mblnr mjahr budat

from mkpf

into table it_mkpf

for all entries in it_mseg

where mblnr = it_mseg-mblnr

and mjahr = it_mseg-mjahr

AND budat IN s_budat. "<<<

And don't forget to loop on your it_mkpf first, because it is your shortes table. It may not contain entries, the above tables do.

Regards

Tamá

Read only

Former Member
0 Likes
995

Hi,

Joining more than 3 tables is not advisable, so try to create a veiw in SE11 for the same with the same conditions and use it in ur program.

Regards,

Padmam.

Read only

Former Member
0 Likes
995

Consider these 4 tables. MARA , MARC , MARD , MAKT.

then select query will be to join all these 4 tables.

Select AMATNR AMTART BWERKS CEINME CSPEME DMAKTX

FROM MARA AS A INNER JOIN MARC AS B ON

AMATNR = BMATNR INNER JOIN MARD AS C ON

BMATNR = CMATNR INNER JOIN MAKT AS D ON

CMATNR = DMATNR INTO CORRESPONDING FIELDS OF TABLE

ITAB WHERE A~MATNR IN SO_MATNR.

Note : SO_MATNR is the variable of selection screen.

Using these select query you can get the field from all 4 tables.

Pradip Pawar.

give points if answer is valuable

Read only

Former Member
0 Likes
995

hi consider we want to retrieve data from these 4 tables MARA , MARC ,MARD , MAKT........Then our select query will be like this.

SELECT AMATNR AMTART BWERKS CLABST D~MAKTX FROM

MARA AS A INNER JOIN MARC AS B ON

AMATNR = BMATNR INNER JOIN MARD AS C ON

BMATNR = CMATNR INNER JOIN MAKT AS D ON

CMATNR = DMATNR INTO CORRESPONDING FIELDS OF TABLE ITAB

WHERE A~MATNR IN SO_MATNR.

note : SO_MATNR will be variable in selection screen.

by using these you will get fields from all 4 tables.

Pradip Pawar.

Give points if ans is valuable