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

SQL-Performance issue with VBAP table

Former Member
0 Likes
855

Hi Guys,

I have a query on table VBAP which fetches data based on date-time stamp and few other fields. Date-tme fields are always filled. If no plant is additionally entered, query runs for about 20 minutes. However, when user enters a plant, query runs for ever (Last run took about 16 hours). I tried tweaking the "where clause" a bit with no sign of improved performance. I really don't understand why should plant mess with the index.

Your replies are appreciated.

Thanks

Yogi

SELECT bvbeln bposnr buepos bmatnr bwerks bmeins b~objnr

berdat cwebaz cplifz efabkl e~pipatg

INTO TABLE pt_order

FROM vbak AS a

INNER JOIN vbap AS b

ON avbeln = bvbeln

INNER JOIN marc AS c

ON bmatnr = cmatnr AND

bwerks = cwerks

INNER JOIN vbuk AS d

ON avbeln = dvbeln

INNER JOIN tvst AS e

ON bvstel = evstel

WHERE a~vkorg IN s_vkorg

AND a~auart IN s_auart

AND ( ( ( berdat LT s_erdat-high ) OR ( berdat EQ s_erdat-high

AND b~erzet LE p_totim ) )

AND ( ( berdat GT s_erdat-low ) OR ( berdat EQ s_erdat-low

AND b~erzet GE p_frtim ) ) )

AND b~werks IN s_werks

AND b~abgru IN s_abgru

AND c~mtvfp IN s_mtvfp

AND d~cmgst IN s_cmgst.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
781

Hi,

your query seems to have been fetching data from the tables:

vbap

marc

tvst

so, I think you can modify your query with the above 3 tables as under:

SELECT bvbeln bposnr buepos bmatnr bwerks bmeins b~objnr

berdat cwebaz cplifz efabkl e~pipatg

INTO TABLE pt_order

FROM vbap AS b

INNER JOIN marc AS c

ON bmatnr = cmatnr

AND

bwerks = cwerks

INNER JOIN tvst AS e

ON bvstel = evstel

WHERE

AND ( ( ( berdat LT s_erdat-high ) OR ( berdat EQ s_erdat-high

AND b~erzet LE p_totim ) )

AND ( ( berdat GT s_erdat-low ) OR ( berdat EQ s_erdat-low

AND b~erzet GE p_frtim ) ) )

AND b~werks IN s_werks

AND b~abgru IN s_abgru

AND c~mtvfp IN s_mtvfp.

and test the changes how it is working for you.

Please make changes as the per above suggestions and let me know how it worked for you.

Thanks,

Vishnu.

5 REPLIES 5
Read only

Former Member
0 Likes
782

Hi,

your query seems to have been fetching data from the tables:

vbap

marc

tvst

so, I think you can modify your query with the above 3 tables as under:

SELECT bvbeln bposnr buepos bmatnr bwerks bmeins b~objnr

berdat cwebaz cplifz efabkl e~pipatg

INTO TABLE pt_order

FROM vbap AS b

INNER JOIN marc AS c

ON bmatnr = cmatnr

AND

bwerks = cwerks

INNER JOIN tvst AS e

ON bvstel = evstel

WHERE

AND ( ( ( berdat LT s_erdat-high ) OR ( berdat EQ s_erdat-high

AND b~erzet LE p_totim ) )

AND ( ( berdat GT s_erdat-low ) OR ( berdat EQ s_erdat-low

AND b~erzet GE p_frtim ) ) )

AND b~werks IN s_werks

AND b~abgru IN s_abgru

AND c~mtvfp IN s_mtvfp.

and test the changes how it is working for you.

Please make changes as the per above suggestions and let me know how it worked for you.

Thanks,

Vishnu.

Read only

Former Member
0 Likes
781

First thing is avoid joining more than 3 tables. So split your query, use select for all entries construct (with an initial check on the driver table). Select the data roughly in the same order as they appear in the table.

Read only

former_member282823
Active Participant
0 Likes
781

Hi,

dont use so many inner joins in the query...may be you can split the query aand try...

Regards,

Ramesh.

Read only

Former Member
0 Likes
781

Difficult to say without more information, so run a SQL trace through ST05 to pinpoint where the issue is. At a guess it's table-scanning somewhere.

What database platform are you on? Do you have any custom indexes on VBAP?

Read only

Former Member
0 Likes
781

ST05 trace revealed that MARC table was executed in interation when user entered plant on the selection-screen. I split the query such that data from transaction tables and master tables are fetched separately.