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

Oute Join and Inner Join

Former Member
0 Likes
939

Hi,

I need to join three tables, based on some conditions (EKPO, EKBE and EKKN Note: All PO line items from EKPO will have a movement associated in the EKBE Table. Capture all PO line items where no matches found in the EKPO-EKBE join)

for the above requirement shall I write my query like this?

SELECT ekpo~ebeln

ekpo~ebelp

ekpo~loekz

ekpo~txz01

ekpo~matnr

ekpo~bukrs

ekpo~werks

ekpo~menge

ekpo~meins

ekpo~knttp

ekbe~vgabe

ekbe~bwart

ekbe~menge

ekbe~dmbtr

ekbe~shkzg

ekkn~sakto

ekkn~kostl

ekkn~ps_psp_pnr

INTO CORRESPONDING FIELDS OF TABLE i_podata

FROM ekpo LEFT OUTER JOIN ekbe ON ekbeebeln = ekpoebeln AND

ekbeebelp = ekpoebelp

INNER JOIN ekkn ON ekknebeln = ekpoebeln AND

ekknebelp = ekpoebelp

WHERE ekpo~werks IN s_werks AND

ekpo~ebeln IN s_ebeln.

Shall I use both Outer Join and Inner join in one Query?

Please correcte me.

Thanks

Frank Rex

Hi,

I need to join three tables, based on some conditions (EKPO, EKBE and EKKN Note: All PO line items from EKPO will have a movement associated in the EKBE Table. Capture all PO line items where no matches found in the EKPO-EKBE join)

for the above requirement shall I write my query like this?

SELECT ekpo~ebeln

ekpo~ebelp

ekpo~loekz

ekpo~txz01

ekpo~matnr

ekpo~bukrs

ekpo~werks

ekpo~menge

ekpo~meins

ekpo~knttp

ekbe~vgabe

ekbe~bwart

ekbe~menge

ekbe~dmbtr

ekbe~shkzg

ekkn~sakto

ekkn~kostl

ekkn~ps_psp_pnr

INTO CORRESPONDING FIELDS OF TABLE i_podata

FROM ekpo LEFT OUTER JOIN ekbe ON ekbeebeln = ekpoebeln AND

ekbeebelp = ekpoebelp

INNER JOIN ekkn ON ekknebeln = ekpoebeln AND

ekknebelp = ekpoebelp

WHERE ekpo~werks IN s_werks AND

ekpo~ebeln IN s_ebeln.

Shall I use both Outer Join and Inner join in one Query?

Please correcte me.

Thanks

Frank Rex

5 REPLIES 5
Read only

Former Member
0 Likes
864

Hi,

You can use both inner join and outer join in the same select statement.

Ensure first all the inner joins between tables are declared and put the left outer join at the end.

Some sample code for your reference:

SELECT

AVBELN AKUNNR ABSTNK ABSTDK AVKORG AVTWEG AAUART AKNUMV

BPOSNR BMATNR BWERKS BSPART BLGORT BKZWI1

SUM( BKWMENG ) AS KWMENG DBZIRK D~VKGRP

EDISPO EPRCTR

FROM VBAK AS A INNER JOIN VBAP AS B ON AVBELN EQ BVBELN

INNER JOIN VBPA AS C ON CVBELN EQ BVBELN

INNER JOIN KNVV AS D ON DKUNNR EQ AKUNNR

AND DVKORG EQ AVKORG AND DVTWEG EQ AVTWEG

LEFT OUTER JOIN MARC AS E ON E~MATNR EQ

BMATNR AND EWERKS EQ B~WERKS

INTO CORRESPONDING FIELDS OF TABLE IT_ORDERS

WHERE A~VKORG IN SO_VKORG

AND A~VTWEG IN SO_VTWEG

AND A~KUNNR IN SO_KUNNR

AND A~ERDAT IN SO_ERDAT

AND A~AUART IN ('ZFOR','ZROR','ZEOR','ZDXR','ZXOR','ZRM1','ZGOR','ZSOR')

AND B~MATNR IN SO_MATNR

AND B~WERKS IN SO_WERKS

AND B~SPART IN SO_SPART

AND B~ABGRU EQ SPACE

AND A~LIFSK EQ SPACE

AND A~FAKSK EQ SPACE

AND B~VSTEL IN SO_VSTEL

AND B~LGORT IN SO_LGORT

AND C~KUNNR IN SO_SHIP

AND C~PARVW EQ 'WE'

AND D~VKGRP IN SO_VKGRP

AND D~BZIRK IN SO_BZIRK

AND B~LGORT NE '0950'

GROUP BY AVBELN AKUNNR ABSTNK ABSTDK

AVKORG AVTWEG AAUART AKNUMV B~POSNR

BMATNR BWERKS BSPART BKZWI1 D~BZIRK

DVKGRP BLGORT EDISPO EPRCTR E~MATGR.

Lakshminarayanan.

P.S.Mark all helpful answers for points.

Read only

Former Member
0 Likes
864

Hi,

I think it's better to use 4 Internal Table, like this:

1. Select from EKPO into Internal IT_EKPO
2. Select from EKBE into Internal IT_EKBE
   with: FOR ALL ENTRIES IN IT_EKPO
         WHERE ebeln = TIT_EKPO-ebeln.
3. Select from EKKN into Internal IT_EKKN
   with: FOR ALL ENTRIES IN IT_EKPO
         WHERE ebeln = TIT_EKPO-ebeln
               EBELP = TIT_EKPO-EBELP.
4. Join table IT_EKPO, IT_EKBE and IT_EKKN into one Internal Table as the Result Table by Looping process.

I hope this , help u.

Regards,

Read only

Former Member
0 Likes
864

Hi Frank,

Use <b>Inner Join</b> for the same

Regards,

Santosh

Read only

dani_mn
Active Contributor
0 Likes
864

Outer join will do the job for you.

Because inner join skips the record where no matches found.

Regards,

Wasim Ahmed

Read only

Former Member
0 Likes
864

Using Inner Join You may miss out some fields as you should be careful to choose all the key fields. Instead you do also READ TABLE with BINARY SEARCH