‎2006 Nov 24 1:59 PM
Hi, I want to optimize the next select.... it tooks almost 4 minutes to execute
vbpa have 5.200.182 records
vbap have 1.344.536 records
SELECT DISTINCT akunnr bwerks
INTO TABLE t_cus_werk
FROM ( vbpa AS a INNER JOIN vbap AS b ON avbeln = bvbeln )
WHERE b~werks = p_werks AND
b~erdat IN r_date.
If we could reduce the time to half
Best regards
Juan
‎2006 Nov 24 2:51 PM
Hi Juan,
It is basically a flawed approach. Getting a few records of master data searching a lot of transactional data is not the best of solutions.
Whatever might be the optimization you do, you would endup selecting all the records from atleast one of the table, which hurts the performance.
You should probably sit with your functional consultant for better alternatives.
Regards,
Ravi Kanth Talagana
‎2006 Nov 24 2:03 PM
Hi,
U can try b y breaking the inner join into individual select statements.
Sandeep
‎2006 Nov 24 2:07 PM
I would put the VBAP table first in the Inner Join.
otherwise, can you add a restriction on VBAK( vkorg... ) for eg ?
Then Join VBAK>VBAP>VBPA...
This should be much better !
Erwan
‎2006 Nov 24 2:09 PM
HI,
Try by using separate select statements..
select distinct kunnr from <table eg.a> into <internal table eg.itab> where condition.
select distinct fieds from <table eg.b> into table< itab2 ><b>for all entries</b> in itab1 where condition.
reward if helpful.
regards,
AJith
‎2006 Nov 24 2:09 PM
use for all entries ...
first select all the entries into it_vbap ..
select vbeln ...
into table it_vbap
where vbeln in s_vbeln
* werks = p_werks
* erdat in r_date.
select kunnr
werks
into table t_cusweek
from vbpa for all entries in it_vbap
where vbeln = it_vbap-vbeln
werks = p_werks
erdat in r_date.sort t_cusweek by kunnr werks.
delete adjacent duplicates t_cusweek comparing kunnr werks.
this will fetch u the distinct records limiting the number of searches .
regards,
vijay
‎2006 Nov 24 2:18 PM
Thanks to all
vijay, ur solution is very interesting, but "in s_vbeln" is confusing me.
Regards
‎2006 Nov 24 2:19 PM
Hi,
Vijay's querry looking good but before using the second select stmt for all entries pl check the content of the internal table it_vbap .
Just add the following before the second select:
IF NOT it_vbap[] IS INITIAL.
....
...
ENDIF.
Cheers.
‎2006 Nov 24 2:21 PM
:):):)
juan ..
its ur sales order range ..
<b>select-options: s_vbeln for vbak-vbeln .</b>
i hope u will be doing for the range of sales orders right ,
so select the entries into ur table based on that ..
regards,
vijay
‎2006 Nov 24 2:22 PM
‎2006 Nov 24 2:26 PM
thanks for the back up ..sunanda ..
forgot to add that ..
juan
before second select
do this
if not it_vbap[] is initial.
select ....
....
for all entries in it_vbap..
endif.
‎2006 Nov 24 2:31 PM
:):):)
i need all the customers from the selected plant.
The problem is because in kna1 not all the customers have plant... so i need to go to vbap
Regards
‎2006 Nov 24 2:14 PM
Hi Juan,
Please try this.
SELECT akunnr bwerks
INTO TABLE t_cus_werk
FROM ( vbpa AS a INNER JOIN vbap AS b ON avbeln = bvbeln )
WHERE b~werks = p_werks AND
b~erdat IN r_date.
SORT t_cust_werk.
DELETE ADJACENT DUPLICATES FROM t_cust_werk.
Also please check this links for performance tuning tips.
http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm
http://www.sap-img.com/abap/abap-fine-tuning.htm
Hope this will help.
Regards,
Ferry Lianto
‎2006 Nov 24 2:47 PM
ERDAT is not an index field on VBAP, but it is on VBAK. So, try:
SELECT DISTINCT a~kunnr b~werks
INTO TABLE t_cus_werk
FROM vbpa AS a
INNER JOIN vbap AS b
ON a~vbeln = b~vbeln
INNER JOIN vbak AS c
ON a~vbeln = c~vbeln
WHERE b~werks = p_werks AND
c~erdat IN r_date.
Rob
‎2006 Nov 24 2:51 PM
Hi Juan,
It is basically a flawed approach. Getting a few records of master data searching a lot of transactional data is not the best of solutions.
Whatever might be the optimization you do, you would endup selecting all the records from atleast one of the table, which hurts the performance.
You should probably sit with your functional consultant for better alternatives.
Regards,
Ravi Kanth Talagana
‎2006 Nov 24 3:00 PM
As I told you before try the Join between !
VBAk // VBAP // VBPA !
This should be much better !
‎2006 Nov 24 7:17 PM