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

Select Join Performance

Former Member
0 Likes
4,388

Hi,

I have a performance problem with this select statement: Takes 30 to 50 secs.

    SELECT k~ebeln  k~lifnr  k~ekgrp  k~ekorg  k~bukrs  k~bsart
           k~bstyp  k~bedat  k~reswk  k~spras  k~adrnr
           k~waers p~ebelp  p~pstyp  p~werks  p~matnr  p~matkl  p~txz01
           p~idnlf  p~labnr
           p~elikz  p~erekz  p~knttp  p~vrtkz  p~meins  p~mfrpn
            p~effwr p~netpr p~peinh p~bprme
           t~etenr  t~eindt  t~menge  t~wemng  t~slfdt  t~mahnz
           INTO CORRESPONDING FIELDS OF TABLE g_i_tab1
           FROM  ekko    AS k
           JOIN  ekpo    AS p
           ON    p~ebeln =  k~ebeln
           JOIN  eket    AS t
           ON    t~ebeln =  k~ebeln  AND
                 t~ebelp =  p~ebelp
           WHERE k~lifnr IN s_lifnr  AND
                 k~ekorg IN s_ekorg  AND
                 k~ekgrp IN s_ekgrp  AND
                 k~bedat IN s_bedat  AND
                 k~ebeln IN s_ebeln  AND
                 k~bstyp IN s_bstyp  AND
                 k~bsart IN s_bsart  AND
                 k~loekz =  space    AND
                 p~matnr IN s_matnr  AND
                 p~werks IN s_werks  AND
                 p~bstyp IN s_bstyp  AND
                 p~loekz =  space    AND
                 p~elikz IN r_elikz  AND
                 p~matkl IN s_matkl  AND
                 p~pstyp IN s_pstyp  AND
                 p~knttp IN s_knttp  AND
                 p~kanba <> 'Y'      AND
                 t~eindt IN s_eindt  AND
                 t~menge >  0        AND
                 t~menge >  t~wemng.

The SQL-Trace (ST05) shows two nested loops, the selection starts always with EKKO

I wonder whether I can force the System to start the selection with Table EKPO, using a certain Index?

(When I count the number of entries with SE16N it takes only 1 sec and I should have the Unique Index to read the other two tables.)

What can I do?

Best regards

Jens

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,786

Can you indicate your mandatory selection parameters? What is the index that it is currently hitting?

If Vendor or BEDAT is filled, I would assume that your query always go after the respective indexes... If you can always ensure that Vendor, EKORG, EKGRP and BEDAT is populated, your query should be faster or BSTYP and BEDAT would give you good results?

43 REPLIES 43
Read only

0 Likes
402

Hi,

summary agreed, Herman

I am not so familliar with these MM and SD tables (and have no access to a system to look it up now).

Is MENGE a real number on DB Level?

SAP has quite a lot num-values that are stored as chars, so it might be neccessary to put in some

num-conversion stuff in addition to build a working index. And it must have of course the join fields in addition.

Volker

Read only

former_member186741
Active Contributor
0 Likes
402

I don't know if anyone has already suggested something like this but it might be worth trying to split the select

like the following to get the key fields.

SELECT ebeln ebelp

INTO CORRESPONDING FIELDS OF TABLE g_ekpo_keys "sorted on ebeln ebelp

FROM ekpo

WHERE matnr IN s_matnr AND

werks IN s_werks AND

bstyp IN s_bstyp AND

loekz = space AND

elikz IN r_elikz AND

matkl IN s_matkl AND

pstyp IN s_pstyp AND

knttp IN s_knttp AND

kanba 'Y' .

if g_ekpo_keys is not initial.

SELECT kebeln klifnr kekgrp kekorg kbukrs kbsart

kbstyp kbedat kreswk kspras k~adrnr

kwaers pebelp ppstyp pwerks pmatnr pmatkl p~txz01

pidnlf plabnr

pelikz perekz pknttp pvrtkz pmeins pmfrpn

peffwr pnetpr ppeinh pbprme

tetenr teindt tmenge twemng tslfdt tmahnz

INTO CORRESPONDING FIELDS OF TABLE g_i_tab1

FROM ekpo AS p

JOIN ekko AS k

ON kebeln = pebeln

JOIN eket AS t

ON tebeln = pebeln AND

tebelp = pebelp

for all entries in g_ekpo_keys

WHERE p~ebeln = g_ekpo_keys-ebeln and

pebelp = g_ekpo_keysebelp and

k~lifnr IN s_lifnr AND

k~ekorg IN s_ekorg AND

k~ekgrp IN s_ekgrp AND

k~bedat IN s_bedat AND

k~ebeln IN s_ebeln AND

k~bstyp IN s_bstyp AND

k~bsart IN s_bsart AND

k~loekz = space AND

t~eindt IN s_eindt AND

t~menge > 0 AND

tmenge > twemng.

endif.

Read only

Former Member
0 Likes
402

Hi,

thanks for your ideas and your commitment.

The most promising path to a real solution seems to be the KEEP pool as Volker suggested.

The alternative seems to be, to select schedulling agreements and purchase orders sepeparately as Kris suggested.

Best regards

Jens

Read only

Former Member
0 Likes
402

pls use this function ME_READ_HISTORY for po history.