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 innerjoin between 5 tables the syntax pls

aarif_baig
Active Participant
2 REPLIES 2

Former Member
0 Kudos

See the syntax :

REPORT ZTEST3 line-size 400.

TABLES: EKKO, LFA1, MAKT, EKET, EKPO, cdhdr.

*Data Declaration

*----


TYPES: BEGIN OF FINAL,

ebeln type ekko-ebeln,

BEDAT type ekko-bedat,

lifnr type ekko-lifnr,

ernam type ekko-ernam,

name1 type lfa1-name1,

matnr type ekpo-matnr,

eindt type eket-eindt,

MAKTX type MAKT-MAKTX,

MBLNR type MSEG-MBLNR,

eldat type eket-eindt,

end of FINAL.

DATA: ITAB TYPE STANDARD TABLE OF FINAL INITIAL SIZE 10 WITH HEADER LINE.

  • all ALV declarations

*----


type-pools: slis. "ALV Declarations

DATA: fieldcatalog TYPE slis_t_fieldcat_alv with header line,

G_REPID TYPE SY-REPID,

GS_PRINT TYPE SLIS_PRINT_ALV,

GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,

GT_EVENTS TYPE SLIS_T_EVENT,

GT_SORT TYPE SLIS_T_SORTINFO_ALV,

GS_LAYOUT TYPE SLIS_LAYOUT_ALV,

COL_POS TYPE I.

*----


  • -----------------SELECTION SCREEN----------------------

selection-screen begin of block b1 with frame title text-001.

select-options podate for EKKO-bedat.

selection-screen end of block b1.

*----


*................... GET DATA..................

SELECT EKKO~EBELN

EKKO~BEDAT

EKKO~LIFNR

EKKO~ERNAM

LFA1~NAME1

MAKT~MATNR

EKET~EINDT

MAKT~MAKTX

MSEG~MBLNR

eket~eindt

INTO CORRESPONDING FIELDS OF ITAB

FROM

( EKKO INNER JOIN LFA1

ON EKKOLIFNR = LFA1LIFNR

INNER JOIN MSEG

ON EKKOEBELN = MSEGEBELN

INNER JOIN MKPF

ON MSEGMBLNR = MKPFMBLNR

INNER JOIN EKPO

ON EKKOEBELN = EKPOEBELN

INNER JOIN MAKT

ON EKPOMATNR = MAKTMATNR

INNER JOIN EKET

ON EKKOEBELN = EKETEBELN

)

WHERE EKKO~BEDAT IN PODATE .

APPEND ITAB. CLEAR ITAB.

ENDSELECT.

Do not use joins more than 3 tables ,if you use you get bad performance.

Thanks

Seshu

0 Kudos

That example is even worse because it uses INTO CORRESPONDING and SELECT...ENDSELECT syntax. Please, let me modify it Seshu:


SELECT EKKO~EBELN
EKKO~BEDAT
EKKO~LIFNR
EKKO~ERNAM
LFA1~NAME1
MAKT~MATNR
EKET~EINDT
MAKT~MAKTX
MSEG~MBLNR
eket~eindt

INTO TABLE ITAB
FROM
( EKKO INNER JOIN LFA1
ON EKKO~LIFNR = LFA1~LIFNR
INNER JOIN MSEG
ON EKKO~EBELN = MSEG~EBELN
INNER JOIN MKPF
ON MSEG~MBLNR = MKPF~MBLNR
INNER JOIN EKPO
ON EKKO~EBELN = EKPO~EBELN
INNER JOIN MAKT
ON EKPO~MATNR = MAKT~MATNR
INNER JOIN EKET
ON EKKO~EBELN = EKET~EBELN
)
WHERE EKKO~BEDAT IN PODATE .

For this to work, your internal table ITAB must have the same column structure as the colums you're selecting from the different tables.

Nevertheless, always avoid joining more than three tables at a time. You can select from three tables and then use FOR ALL ENTRIES for selecting the remaining needed data into a second itab.

Regards