<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Tune this Select Statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251203#M1014780</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt;I didnt exactly get what you are trying to say.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By going to ST05 you can turn on tracing, run your select and then look at what is called the explain plan from the DB.  This explain plan will reveal everything that we'll need in order to tell why it is going slowly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;SELECT a~vbeln " Sales Order&lt;/P&gt;&lt;P&gt;&amp;gt;a~kunnr " Customer Number&lt;/P&gt;&lt;P&gt;&amp;gt;b~gbstk " Processing Status&lt;/P&gt;&lt;P&gt;&amp;gt;b~cmgst " Status of credit checks&lt;/P&gt;&lt;P&gt;&amp;gt;FROM vbpa AS a INNER JOIN vbuk AS b&lt;/P&gt;&lt;P&gt;&amp;gt;ON a&lt;SUB&gt;vbeln EQ b&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;&amp;gt;NTO TABLE l_i_vbpa_vbuk&lt;/P&gt;&lt;P&gt;&amp;gt;FOR ALL ENTRIES IN i_kna1&lt;/P&gt;&lt;P&gt;&amp;gt;WHERE a~kunnr EQ i_kna1-kunnr.&lt;/P&gt;&lt;P&gt;&amp;gt;SORT : l_i_vbpa_vbuk.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Taking another look at your SQL statement and checking how the tables are setup in a standard SAP environment, I would say that the reason it is running slowly is because the VBPA table has no secondary indexes and therefore searchs by Kunnr are going to always be exhaustive and sequential.  The VBPA table is optimized for the retrieval of records based on knowing the document number.  In addition to this, as you'll see in a trace, becuase it is using For All Entries it is actually chunked into a number of executions of the SQL statement usually each one executing for around 4 or 5 Kunnrs, each of these executions will scan the entire table each time because each chunk executes independently of the others.  In that case the for all entires is atleast some what better then individual select singles in a loop (by a factor of 4 to 5), but the fact that it doesn't have an index is going to cause you issues no matter what.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The join itself would be ok if it was able to use an index for Kunnr because the VBUK table will be joined in based on the values of VBELN which is a key.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of the options that I would give you is the putting of a new secondary index on the VBPA table on the fields MANDT, and KUNNR.  Another better option is to take a look at the VAKPA table (Sales Index: Orders by Partner Function) which is optimized to select based on Kunnr.  This table VAKPA is optimized for exactly what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will spead things up for you a lot, because if you think your current select statement is slow you should see how slow it will be as the VBPA table grows in size over time, since it will mean that every search will have to sequentially go through more records:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;SELECT a~vbeln " Sales Order&lt;/P&gt;&lt;P&gt;&amp;gt;a~kunnr " Customer Number&lt;/P&gt;&lt;P&gt;&amp;gt;b~gbstk " Processing Status&lt;/P&gt;&lt;P&gt;&amp;gt;b~cmgst " Status of credit checks&lt;/P&gt;&lt;P&gt;&amp;gt;FROM VAKPA AS a INNER JOIN vbuk AS b&lt;/P&gt;&lt;P&gt;&amp;gt;ON a&lt;SUB&gt;vbeln EQ b&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;&amp;gt;NTO TABLE l_i_vbpa_vbuk&lt;/P&gt;&lt;P&gt;&amp;gt;FOR ALL ENTRIES IN i_kna1&lt;/P&gt;&lt;P&gt;&amp;gt;WHERE a~kunnr EQ i_kna1-kunnr.&lt;/P&gt;&lt;P&gt;&amp;gt;SORT : l_i_vbpa_vbuk.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note - Only difference is the changeing of VBPA to VAKPA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even if you do what one of the other suggestions said to to and split the join into two selects via a For All Entries, you would still have this same issue unless you used VAKPA instead of VBPA becuase the first select would be doing sequeuntial reads.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On a side note, something to start doing is using ST05 and read up on DB explain plans, it will allow you to quickly resolve issues like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, after this change if it doesn't work a lot faster, ask you DBA to run statistics on the tables VBUK and VAKPA.  If the statistics are not up to date then the DB optimizer may make strange decisions on the join.&lt;/P&gt;&lt;P&gt;~Ian&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Ian Maxwell on Aug 4, 2008 5:29 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 04 Aug 2008 21:28:47 GMT</pubDate>
    <dc:creator>ian_maxwell2</dc:creator>
    <dc:date>2008-08-04T21:28:47Z</dc:date>
    <item>
      <title>Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251193#M1014770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My Aim to fetch Sales Orders for the customers Number is I have in i_kna1.&lt;/P&gt;&lt;P&gt;I coded as below but it takes lots of time as no proper index is used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any other way to fetch sales orders for customers or any clues on how to improve this statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Fetch the sales order numbers w.r.t customer from partner data&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  SELECT a~vbeln                       " Sales Order&lt;/P&gt;&lt;P&gt;         a~kunnr                       " Customer Number&lt;/P&gt;&lt;P&gt;         b~gbstk                       " Processing Status&lt;/P&gt;&lt;P&gt;         b~cmgst                       " Status of credit checks&lt;/P&gt;&lt;P&gt;         FROM vbpa AS a INNER JOIN vbuk AS b&lt;/P&gt;&lt;P&gt;         ON a&lt;SUB&gt;vbeln EQ b&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;         INTO TABLE l_i_vbpa_vbuk&lt;/P&gt;&lt;P&gt;         FOR ALL ENTRIES IN i_kna1&lt;/P&gt;&lt;P&gt;        WHERE a~kunnr EQ i_kna1-kunnr.&lt;/P&gt;&lt;P&gt;  SORT : l_i_vbpa_vbuk.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Kiran&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 15:31:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251193#M1014770</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-04T15:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251194#M1014771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT a~vbeln " Sales Order
a~kunnr " Customer Number
b~gbstk " Processing Status
b~cmgst " Status of credit checks
FROM vbpa AS a INNER JOIN vbuk AS b
ON a~vbeln EQ b~vbeln
INTO TABLE l_i_vbpa_vbuk
FOR ALL ENTRIES IN i_kna1
WHERE a~kunnr EQ i_kna1-kunnr.
SORT : l_i_vbpa_vbuk.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My recomendation would be to do a trace via ST05 and take a look at the explain plan that is being used on the database (what DB are you using? Oracle?).  If you can post the explain plan on here I'll be able to tell you more of what is going on.  With this explain plan we'll be able to tell a few things about the optimizer:&lt;/P&gt;&lt;P&gt;- The order that the tables will be joined in&lt;/P&gt;&lt;P&gt;- The inexes that will be used&lt;/P&gt;&lt;P&gt;- The alogithms that will be used for searching and joining&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;~Ian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 15:43:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251194#M1014771</guid>
      <dc:creator>ian_maxwell2</dc:creator>
      <dc:date>2008-08-04T15:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251195#M1014772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kiran,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try using the BAPI &lt;EM&gt;BAPI_SALESORDER_GETLIST&lt;/EM&gt;, you can pass the following parameters to the BAPI &lt;/P&gt;&lt;P&gt;CUSTOMER_NUMBER      &lt;/P&gt;&lt;P&gt;SALES_ORGANIZATION   &lt;/P&gt;&lt;P&gt;MATERIAL             &lt;/P&gt;&lt;P&gt;DOCUMENT_DATE        &lt;/P&gt;&lt;P&gt;DOCUMENT_DATE_TO     &lt;/P&gt;&lt;P&gt;PURCHASE_ORDER       &lt;/P&gt;&lt;P&gt;TRANSACTION_GROUP    &lt;/P&gt;&lt;P&gt;PURCHASE_ORDER_NUMBER&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps...&lt;/P&gt;&lt;P&gt;Amit Purohit.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 16:41:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251195#M1014772</guid>
      <dc:creator>former_member584282</dc:creator>
      <dc:date>2008-08-04T16:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251196#M1014773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;If you want to use the SELECT statement only then we can do this way by filtering -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort i_kna1 by keyfields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if i_kna1[] is not initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from vbpa&lt;/P&gt;&lt;P&gt;into table i_vbpa&lt;/P&gt;&lt;P&gt;for all entries in i_kna1 &lt;/P&gt;&lt;P&gt;where kunnr = i_kna1-kunnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort i_vbpa by keyfields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if i_vbpa[] is not initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from vbuk&lt;/P&gt;&lt;P&gt;into table i_vbuk&lt;/P&gt;&lt;P&gt;for all entries in i_vbpa&lt;/P&gt;&lt;P&gt;where vbeln = i_vbpa-vbeln.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Chandralekha.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 16:55:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251196#M1014773</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-04T16:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251197#M1014774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I didnt exactly get what you are trying to say.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any more clues?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Kiran&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 16:57:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251197#M1014774</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-04T16:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251198#M1014775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Amit,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cannot use a FM because I will have to loop at KAN1 Itab again which will bring down performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ANy more clues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Kiran&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 17:52:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251198#M1014775</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-04T17:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251199#M1014776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This message was moderated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 18:21:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251199#M1014776</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-04T18:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251200#M1014777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Simply run a performance trace on the "sold-to party" search functionality for VA02.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 19:13:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251200#M1014777</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-04T19:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251201#M1014778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That trace will probably reveal that table &lt;STRONG&gt;VAKPA&lt;/STRONG&gt; is the one to use when trying to quickly find sales orders for given partner numbers. &lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 20:35:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251201#M1014778</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2008-08-04T20:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251202#M1014779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually a view based on that table. Either should be OK.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 20:44:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251202#M1014779</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-04T20:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251203#M1014780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt;I didnt exactly get what you are trying to say.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By going to ST05 you can turn on tracing, run your select and then look at what is called the explain plan from the DB.  This explain plan will reveal everything that we'll need in order to tell why it is going slowly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;SELECT a~vbeln " Sales Order&lt;/P&gt;&lt;P&gt;&amp;gt;a~kunnr " Customer Number&lt;/P&gt;&lt;P&gt;&amp;gt;b~gbstk " Processing Status&lt;/P&gt;&lt;P&gt;&amp;gt;b~cmgst " Status of credit checks&lt;/P&gt;&lt;P&gt;&amp;gt;FROM vbpa AS a INNER JOIN vbuk AS b&lt;/P&gt;&lt;P&gt;&amp;gt;ON a&lt;SUB&gt;vbeln EQ b&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;&amp;gt;NTO TABLE l_i_vbpa_vbuk&lt;/P&gt;&lt;P&gt;&amp;gt;FOR ALL ENTRIES IN i_kna1&lt;/P&gt;&lt;P&gt;&amp;gt;WHERE a~kunnr EQ i_kna1-kunnr.&lt;/P&gt;&lt;P&gt;&amp;gt;SORT : l_i_vbpa_vbuk.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Taking another look at your SQL statement and checking how the tables are setup in a standard SAP environment, I would say that the reason it is running slowly is because the VBPA table has no secondary indexes and therefore searchs by Kunnr are going to always be exhaustive and sequential.  The VBPA table is optimized for the retrieval of records based on knowing the document number.  In addition to this, as you'll see in a trace, becuase it is using For All Entries it is actually chunked into a number of executions of the SQL statement usually each one executing for around 4 or 5 Kunnrs, each of these executions will scan the entire table each time because each chunk executes independently of the others.  In that case the for all entires is atleast some what better then individual select singles in a loop (by a factor of 4 to 5), but the fact that it doesn't have an index is going to cause you issues no matter what.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The join itself would be ok if it was able to use an index for Kunnr because the VBUK table will be joined in based on the values of VBELN which is a key.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of the options that I would give you is the putting of a new secondary index on the VBPA table on the fields MANDT, and KUNNR.  Another better option is to take a look at the VAKPA table (Sales Index: Orders by Partner Function) which is optimized to select based on Kunnr.  This table VAKPA is optimized for exactly what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will spead things up for you a lot, because if you think your current select statement is slow you should see how slow it will be as the VBPA table grows in size over time, since it will mean that every search will have to sequentially go through more records:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;SELECT a~vbeln " Sales Order&lt;/P&gt;&lt;P&gt;&amp;gt;a~kunnr " Customer Number&lt;/P&gt;&lt;P&gt;&amp;gt;b~gbstk " Processing Status&lt;/P&gt;&lt;P&gt;&amp;gt;b~cmgst " Status of credit checks&lt;/P&gt;&lt;P&gt;&amp;gt;FROM VAKPA AS a INNER JOIN vbuk AS b&lt;/P&gt;&lt;P&gt;&amp;gt;ON a&lt;SUB&gt;vbeln EQ b&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;&amp;gt;NTO TABLE l_i_vbpa_vbuk&lt;/P&gt;&lt;P&gt;&amp;gt;FOR ALL ENTRIES IN i_kna1&lt;/P&gt;&lt;P&gt;&amp;gt;WHERE a~kunnr EQ i_kna1-kunnr.&lt;/P&gt;&lt;P&gt;&amp;gt;SORT : l_i_vbpa_vbuk.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note - Only difference is the changeing of VBPA to VAKPA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even if you do what one of the other suggestions said to to and split the join into two selects via a For All Entries, you would still have this same issue unless you used VAKPA instead of VBPA becuase the first select would be doing sequeuntial reads.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On a side note, something to start doing is using ST05 and read up on DB explain plans, it will allow you to quickly resolve issues like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, after this change if it doesn't work a lot faster, ask you DBA to run statistics on the tables VBUK and VAKPA.  If the statistics are not up to date then the DB optimizer may make strange decisions on the join.&lt;/P&gt;&lt;P&gt;~Ian&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Ian Maxwell on Aug 4, 2008 5:29 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2008 21:28:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251203#M1014780</guid>
      <dc:creator>ian_maxwell2</dc:creator>
      <dc:date>2008-08-04T21:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: Tune this Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251204#M1014781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your big explanation.&lt;/P&gt;&lt;P&gt;I tried with VAKPA too..&lt;/P&gt;&lt;P&gt;But I ended up with a solution to use a view VBAKUK.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks everone for your time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kiran&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2008 18:51:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tune-this-select-statement/m-p/4251204#M1014781</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-06T18:51:01Z</dc:date>
    </item>
  </channel>
</rss>

