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

Help with INNER JOIN

Former Member
0 Likes
526

Hi All,

The following code takes a lot of time to execute. Can anyone suggest to fine tune the following inner join statement.

SELECT aebeln aebelp atxz01 amatnr a~werks

algort amenge ameins anetpr a~peinh

awebaz ainsmk apstyp aknttp a~labnr

akonnr aktpnr aevers akunnr a~adrnr

arevlv aemlif aadrn2 amtart aelikz aretpo

blifnr bekgrp bwaers bbedat b~inco1

binco2 cetenr ceindt cslfdt c~menge

cwemng dbanfn d~bnfpo

INTO TABLE t_po

FROM ekko AS b

INNER JOIN ekpo AS a

ON aebeln EQ bebeln

INNER JOIN eket AS c

ON cebeln EQ aebeln

AND cebelp EQ aebelp

LEFT OUTER JOIN eban AS d

ON aebeln EQ debeln

AND aebelp EQ debelp

WHERE b~ebeln IN s_ebeln "Purchasing Document

AND b~bsart IN s_bsart "Document Type

AND b~loekz EQ space "Deletion Indicator, Header

AND b~lifnr IN s_lifnr "Vendor Number

AND b~ekorg IN s_ekorg "Purchasing Organization

AND b~ekgrp IN s_ekgrp "Purchasing Group

AND b~bedat IN s_bedat "Document Date

AND b~bukrs IN s_bukrs

AND a~elikz = space "delivery not complete

AND a~loekz EQ space "Deletion Indicator, Line

AND a~txz01 IN r_txz01 "Short Text

AND a~matnr IN s_matnr "Material Number

AND a~werks IN s_werks "Plant

AND a~lgort IN s_lgort "Storage Location

AND a~matkl IN s_matkl "Material Group

AND a~idnlf IN s_idnlf "Vendor's Material Number

AND a~pstyp IN r_pstyp "Item Category

AND a~knttp IN s_knttp "Account Assign. Category

AND a~bstae IN s_bstae "Confirmation Control Key

AND c~eindt IN s_eindt. "Item Delivery Date

Regards

Brain

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
494

Check that s_ebeln is not empty before doing the select.

Rob

3 REPLIES 3
Read only

Former Member
0 Likes
495

Check that s_ebeln is not empty before doing the select.

Rob

Read only

0 Likes
494

Also, your last join:


    LEFT OUTER JOIN eban AS d
      ON a~ebeln EQ d~ebeln
      AND a~ebelp EQ d~ebelp

doesn't use an index. Remove this and see if it speeds things up. If it does, see if there's another way to get this data.

Rob

Read only

0 Likes
494

To follow up on Rob's suggestion, BANFN and BNFPO are on EKPO.