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: 

how to use inner joins for 4 0r 5 tables

former_member1242340
Participant
0 Kudos
678

Hai Experts,

plz check my code, n plz help to inner join all the tables

TYPES : BEGIN OF ITAB,

EBELN TYPE EKKO-EBELN, "P.O.NUMBER

AEDAT TYPE EKKO-AEDAT, "DATE

BPRME TYPE EKPO-BPRME, "UNIT PRICE

MENGE TYPE EKPO-MENGE, "Purchase order quantity

WERKS TYPE EKPO-WERKS, "PLANT

BRTWR TYPE EKPO-BRTWR, "Gross order value in PO

STRAS TYPE LFA1-STRAS, "House number and street

LIFNR TYPE LFA1-LIFNR, "VENDOR NO

NAME1 TYPE LFA1-NAME1, "V NAME

ORT01 TYPE LFA1-ORT01, "CITY

LAND1 TYPE LFA1-LAND1, "LAND

PSTLZ TYPE LFA1-PSTLZ, "POSTAL CODE

MAKTX TYPE MAKT-MAKTX, "DESCRIPTION

END OF ITAB.

<b>and i got stucked here:</b>

<u></u>

SELECT EKKO~EBELN

EKKO~AEDAT

EKPO~BPRME

EKPO~MENGE

EKPO~WERKS

EKPO~BRTWR

LFA1~LIFNR

LFA1~STRAS

LFA1~NAME1

LFA1~ORT01

LFA1~LAND1

LFA1~PSTLZ

MAKT~MAKTX

INTO TABLE ITAB

FROM EKKO

INNER JOIN EKPO LFA1 T001W MAKT

ON EKKOEBELN = EKPOEBELN

EKKO~EBELN

WHERE EKKO~EBELN IN S_EBELN.

4 REPLIES 4

Former Member
0 Kudos
135

Hi,

Check the following link:

http://sap-img.com/abap/inner-joins.htm

Regards,

Bhaskar

Former Member
0 Kudos
135

refer 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.

JozsefSzikszai
Active Contributor
0 Kudos
135

hi Rajesh,

you have to join the tables one by one:

SELECT ekko~ebeln

ekko~aedat

ekpo~bprme

ekpo~menge

ekpo~werks

ekpo~brtwr

lfa1~lifnr

lfa1~stras

lfa1~name1

lfa1~ort01

lfa1~land1

lfa1~pstlz

makt~maktx

INTO TABLE itab

FROM ekko AS ekko

INNER JOIN ekpo AS ekpo

ON ekkoebeln EQ ekpoebeln

INNER JOIN lfa1 AS lfa1

ON ekkolifnr EQ lfa1lifnr

INNER JOIN t001w AS t001w

ON ekpowerks EQ t001wwerks

INNER JOIN makt AS makt

ON ekpomatnr EQ MAKTmatnr

WHERE ekko~ebeln IN s_ebeln.

This is the complete SELECT. BUT! The performance will be much better if you take out T001W and MAKT from the INNER JOIN. Do select on these tables in separate steps and merge the internal tables afterwards.

hope this helps

ec

Former Member
0 Kudos
135

Hi

SELECT EKKO~EBELN

EKKO~AEDAT

EKPO~BPRME

EKPO~MENGE

EKPO~WERKS

EKPO~BRTWR

LFA1~LIFNR

LFA1~STRAS

LFA1~NAME1

LFA1~ORT01

LFA1~LAND1

LFA1~PSTLZ

MAKT~MAKTX

INTO TABLE ITAB

FROM EKKO

INNER JOIN EKPO

ON EKKOEBELN = EKPOEBELN join LFA1 on EKKOlifnr = lfa1lifnr join

T001W on ekpowerks = t001Wwerks join MAKT

EKpOmatnr = maktmatnr

WHERE EKKO~EBELN IN S_EBELN.

regards

anji