<?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: Optimising code: to select by keys only? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610457#M869668</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmm.. I can't find that view, but here's a view that looks like a join of VBAK and VBUK&lt;/P&gt;&lt;P&gt;view: VBAKUK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 24 Mar 2008 09:43:34 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-03-24T09:43:34Z</dc:date>
    <item>
      <title>Optimising code: to select by keys only?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610454#M869665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi guys, can anyone tell me if it's better to..&lt;/P&gt;&lt;P&gt;1. select all records with selection that are key fields?&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;2. select all records with selections from non key fields?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't get reliable results due to table buffering.  currently, the 2nd way works faster for me.  See below.&lt;/P&gt;&lt;P&gt;What are you opinions?  Is there a more efficient way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;p.s. I'm doing it this way as I have determined that joining VBAK (sales header) with VBAP (sales item), with the selection parameters I desire is less efficient.  Hence, I'm getting VBAK first before getting the item details&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;#1 -----------------------------------------------------------&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;      SELECT vbak~vbeln&lt;/P&gt;&lt;P&gt;             vbak&lt;SUB&gt;lifsk vbak&lt;/SUB&gt;faksk&lt;/P&gt;&lt;P&gt;             vbuk~lfstk&lt;/P&gt;&lt;P&gt;        INTO CORRESPONDING FIELDS OF TABLE gt_sohdr FROM vbak&lt;/P&gt;&lt;P&gt;        INNER JOIN vbuk ON vbuk&lt;SUB&gt;vbeln = vbak&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;        WHERE vbak~auart IN s_auart&lt;/P&gt;&lt;P&gt;        AND   vbak~vkorg IN s_vkorg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      DELETE gt_sohdr WHERE lfstk NE 'A'.  "hdr: delv stat&lt;/P&gt;&lt;P&gt;      DELETE gt_sohdr WHERE lifsk NE ''.   "delv block&lt;/P&gt;&lt;P&gt;      DELETE gt_sohdr WHERE faksk NE ''.   "bill block&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;#2 -----------------------------------------------------------&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;      SELECT vbak~vbeln&lt;/P&gt;&lt;P&gt;             vbak&lt;SUB&gt;lifsk vbak&lt;/SUB&gt;faksk&lt;/P&gt;&lt;P&gt;             vbuk~lfstk&lt;/P&gt;&lt;P&gt;        INTO CORRESPONDING FIELDS OF TABLE gt_sohdr FROM vbak&lt;/P&gt;&lt;P&gt;        INNER JOIN vbuk ON vbuk&lt;SUB&gt;vbeln = vbak&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;        WHERE vbak~auart IN s_auart&lt;/P&gt;&lt;P&gt;        AND   vbak~vkorg IN s_vkorg&lt;/P&gt;&lt;P&gt;        AND   lfstk EQ 'A'&lt;/P&gt;&lt;P&gt;        AND   lifsk EQ ''&lt;/P&gt;&lt;P&gt;        AND   faksk EQ ''.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 02:34:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610454#M869665</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-24T02:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Optimising code: to select by keys only?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610455#M869666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this WB2_V_VBAK_VBAP2 standard view table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rgds&lt;/P&gt;&lt;P&gt;Vijay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 09:26:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610455#M869666</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-24T09:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Optimising code: to select by keys only?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610456#M869667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To select by rpimary key would be mush faster and efficient &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;since the primary keys will have unique values &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the data operation will be fast&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;also try to use the index of the table if possible&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Shiva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 09:40:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610456#M869667</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-24T09:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Optimising code: to select by keys only?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610457#M869668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmm.. I can't find that view, but here's a view that looks like a join of VBAK and VBUK&lt;/P&gt;&lt;P&gt;view: VBAKUK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 09:43:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610457#M869668</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-24T09:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Optimising code: to select by keys only?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610458#M869669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Wong, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first options is definitely a better option as you can select the entries by the help of primary keys. You will have much less data after the proper filtration of data. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards, &lt;/P&gt;&lt;P&gt;Samantak. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Rewards points for useful answers.&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 16:56:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610458#M869669</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-24T16:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Optimising code: to select by keys only?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610459#M869670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Option 1 ( select all records with selection that are key fields) is definitely better. But in addition to that if you have more condition (might be non-key) it will perform better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is why query 2 is performing better. You have used join, so table bffering has no role&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In #1 &amp;amp; #2 the main condition is same&lt;/P&gt;&lt;P&gt;WHERE vbak~auart IN s_auart&lt;/P&gt;&lt;P&gt;AND vbak~vkorg IN s_vkorg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But in #2 you have specified some more condition - so it is performing better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please close the thread if it is fixed&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 06:36:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610459#M869670</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-25T06:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Optimising code: to select by keys only?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610460#M869671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your second option is not a recommended one. You should not read more than you actually need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In principle, it should not happen that the addition of further select criteria deteriorates the performance. However, in joins the following can happen:&lt;/P&gt;&lt;P&gt;First option starts with the conditions on vbak and joins vbuk, which gives good performance.&lt;/P&gt;&lt;P&gt;Second options, the optimizer thinks that the options on vbuk are more selective and starts on vbuk. In fact this is less effective, so the performance becomes worse.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;+ You should try to add a hint which tells the database the start with the index on vbak &lt;/P&gt;&lt;P&gt;   (database dependent9&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;+ Here a FOR ALL ENTRIES could be a better option, read on vbak first, add the other information with FOR ALL ENTRIES.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;+ I am not sure whether a view will help, it is nothing different than a join&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 09:00:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610460#M869671</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-25T09:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Optimising code: to select by keys only?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610461#M869672</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, thanks for the inputs, everyone.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My findings:&lt;/P&gt;&lt;P&gt;1. Fetching VBAK without selection parameters, then filter, then fetching VBUK is not efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. A view appears slightly faster or gives the same performance.  It could also be my imagination.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. Adding more selection parameters in a JOIN does not deteoriate the performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To try:&lt;/P&gt;&lt;P&gt;4. Get VBAK with selection parameters, filter, then fetch VBUK&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's enough testing for me.  I should get back to more productive work.  Thank you all.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2008 01:12:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimising-code-to-select-by-keys-only/m-p/3610461#M869672</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-26T01:12:47Z</dc:date>
    </item>
  </channel>
</rss>

