<?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: SELECT Query Optimization in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726097#M896820</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1) In the first select,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     avoid using  OR condition. this will take more time.&lt;/P&gt;&lt;P&gt;     avoid NE condition. after populating the data delete the unwanted records.&lt;/P&gt;&lt;P&gt;     make sure the select-options is not initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) before using FOR ALL ENTRIES,&lt;/P&gt;&lt;P&gt;    check &lt;EM&gt;if t_vbak[] is not initial&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;    delete the duplicate entries&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3) avoid using &amp;lt;&amp;gt;, &amp;gt; condition  especially for constants like w&lt;SUB&gt;kwmeng &amp;gt; 0.  see how many records it will fetch with w&lt;/SUB&gt;kwmeng &amp;gt; 0 and without it and see if it makes significant difference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Madhu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 24 Apr 2008 08:16:12 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-04-24T08:16:12Z</dc:date>
    <item>
      <title>SELECT Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726096#M896819</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have requirement to optimize the following query. The requirement is: either a new index need to be created or the SELECT statement need to be changed in order to improve the performance of the SELECT query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; 
select a~vbeln a~auart a~vkorg a~vtweg a~spart
             a~angdt a~bnddt a~guebg a~gueen a~vkgrp
             a~vkbur a~gsber a~kunnr a~erdat a~erzet
             a~waerk a~vbtyp a~autlf a~vsbed a~kvgr1
             a~kvgr2 a~kvgr3 a~kvgr4 a~kvgr5 a~abrvw
             a~abdis
        into table t_vbak
        from vbak as a inner join vbuk as b on b~vbeln = a~vbeln
        where
              ( ( a~erdat &amp;gt; pre_dat ) and
              ( a~erdat &amp;lt;= w_date  ) ) and
              a~vbtyp in s_doccat and
              a~vbeln in s_ordno and
              a~vkorg in s_vkorg and
              a~vtweg in s_vtweg and
              a~spart in s_spart and
              ( ( a~lifsk in s_lifsk ) or
              ( a~lifsk = '  ' ) ) and
              b~abstk ne 'C'.

      
	select  w~mandt
                w~vbeln  w~posnr  w~meins w~matnr w~werks  w~netwr
                w~kwmeng w~vrkme  w~matwa  w~charg w~pstyv
                w~posar  w~prodh  w~grkor  w~antlf  w~kztlf w~lprio
                w~vstel  w~route  w~umvkz  w~umvkn  w~abgru w~untto
                w~awahr  w~erdat  w~erzet  w~fixmg  w~prctr  w~vpmat
                w~vpwrk  w~mvgr1  w~mvgr2  w~mvgr3  w~mvgr4  w~mvgr5
                w~bedae  w~cuobj  w~mtvfp
                x~etenr x~wmeng x~bmeng   x~ettyp  x~wepos  x~abart
                x~edatu x~tddat x~mbdat   x~lddat  x~wadat  x~abruf 
                x~etart x~ezeit
                into table t_vbap
               from  vbap as w inner join vbep as x 
                          on x~vbeln = w~vbeln and
                             x~posnr = w~posnr and
                             x~mandt = w~mandt
         for all entries in t_vbak
         where
                       w~vbeln in s_ordno and
                       w~vbeln = t_vbak-vbeln and
            ( ( ( erdat &amp;gt; pre_dat  and  erdat &amp;lt; p_syndt ) or
            ( erdat = p_syndt and erzet &amp;lt;= p_syntm ) ) ) and
                       w~matnr in s_matnr and
                       w~pstyv in s_itmcat and
                       w~lfrel in s_lfrel and
                       w~abgru = '  ' and
                       w~kwmeng &amp;gt; 0   and
                       w~mtvfp in w_mtvfp  and
                       x~ettyp in w_ettyp  and
                       x~bdart in s_req_tp and
                       x~plart in s_pln_tp and
                       x~etart in s_etart and
                       x~abart in s_abart and
                       ( ( x~lifsp in s_lifsp ) or ( x~lifsp = ' ' ) ).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It would be great if you can suggest some change in the above code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Appreciate your valuable inputs. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Chandravadan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 07:22:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726096#M896819</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T07:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726097#M896820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1) In the first select,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     avoid using  OR condition. this will take more time.&lt;/P&gt;&lt;P&gt;     avoid NE condition. after populating the data delete the unwanted records.&lt;/P&gt;&lt;P&gt;     make sure the select-options is not initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) before using FOR ALL ENTRIES,&lt;/P&gt;&lt;P&gt;    check &lt;EM&gt;if t_vbak[] is not initial&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;    delete the duplicate entries&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3) avoid using &amp;lt;&amp;gt;, &amp;gt; condition  especially for constants like w&lt;SUB&gt;kwmeng &amp;gt; 0.  see how many records it will fetch with w&lt;/SUB&gt;kwmeng &amp;gt; 0 and without it and see if it makes significant difference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Madhu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 08:16:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726097#M896820</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T08:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726098#M896821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Chandravadan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;using NE like you do in &lt;/P&gt;&lt;P&gt;b~abstk ne 'C'&lt;/P&gt;&lt;P&gt;usually result in loss of performance. It is better to use a selection-option with the values you would like to include.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The next thing I would check, if the select statement is able to use the indexes. You can check this in the SQL-Trace (TA ST05). If not you need to rearrange your fields so that an index can be used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Third: You do not check if the table t_vbak is empty after the first select statement. If he is empty all data in the second select-statement is read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards Matthias Nutt&lt;/P&gt;&lt;P&gt;SAP Consulting Switzerland&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 10:25:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726098#M896821</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T10:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726099#M896822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;weird !!!! ???? !!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
where   w~vbeln in s_ordno and
            w~vbeln = t_vbak-vbeln and
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't know what you expect from such a condition!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is a bug, the first line must be delete, it was used in the first select, so the vbeln are in the table t_vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The unique key of VBAP is mandt, vbeln and posnr, will the following conditions really reduce the result set?&lt;/P&gt;&lt;P&gt;Especcially the erdat conditions are so confusing, that you better use it inside the select.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;( ( ( erdat &amp;gt; pre_dat  and  erdat &amp;lt; p_syndt ) or&lt;/P&gt;&lt;P&gt;            ( erdat = p_syndt and erzet &amp;lt;= p_syntm ) ) ) and&lt;/P&gt;&lt;P&gt;                       w~matnr in s_matnr and&lt;/P&gt;&lt;P&gt;                       w~pstyv in s_itmcat and&lt;/P&gt;&lt;P&gt;                       w~lfrel in s_lfrel and&lt;/P&gt;&lt;P&gt;                       w~abgru = '  ' and&lt;/P&gt;&lt;P&gt;                       w~kwmeng &amp;gt; 0   and&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 12:09:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726099#M896822</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T12:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726100#M896823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;Try to avoid joins instead, use for all entries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And using loop update data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2008 21:30:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726100#M896823</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-24T21:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726101#M896824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you did not get the point!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 07:27:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-optimization/m-p/3726101#M896824</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-25T07:27:28Z</dc:date>
    </item>
  </channel>
</rss>

