<?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: Improve performance -  sql statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385443#M812887</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you are using less number of tables then you can go for joins. Otherwise, better use FOR ALL ENTRIES statement. It would not have overload on the server. Everytime the data is fetched only from the internal tables except for the first time. I hope you understand. Get back if u still have queries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if useful. Best of luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Feb 2008 03:35:07 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-02-11T03:35:07Z</dc:date>
    <item>
      <title>Improve performance -  sql statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385441#M812885</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;I am still new to abap. Below is a simple sql that I hope to streamline, so that the performance could be improved. It has taken some amount of time to process. How can I improve the sql below? Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; IF v_vtweg IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;    cond_vtweg = 'vbak~vtweg = v_vtweg'.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF p_werks IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;    cond_werks = 'vbap~werks = p_werks'.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT&lt;/P&gt;&lt;P&gt;    vbap~vbeln    " Order #&lt;/P&gt;&lt;P&gt;    vbap~posnr    " Order Position/Item&lt;/P&gt;&lt;P&gt;    vbak~kunnr    " Customer Code&lt;/P&gt;&lt;P&gt;    kna1~name1    " Customer Name&lt;/P&gt;&lt;P&gt;    vbap~matnr    " Material&lt;/P&gt;&lt;P&gt;    vbap~zlcrd    " CRD&lt;/P&gt;&lt;P&gt;    vbap~zlcrdp2                                            " CRDP2&lt;/P&gt;&lt;P&gt;    vbap~zledd    " EDD/MAD&lt;/P&gt;&lt;P&gt;    vbap~zlfsd    " FSD&lt;/P&gt;&lt;P&gt;    vbap~kwmeng   " Order Qty&lt;/P&gt;&lt;P&gt;    vbap~werks    " Plant&lt;/P&gt;&lt;P&gt;    vbap~lgort    " Sales Org&lt;/P&gt;&lt;P&gt;    vbap~netwr    " Order Amount&lt;/P&gt;&lt;P&gt;    vbak~vtweg    " Dist. Channel&lt;/P&gt;&lt;P&gt;    lips~lgnum    " Warehouse&lt;/P&gt;&lt;P&gt;    lips~vbeln    " Delivery #&lt;/P&gt;&lt;P&gt;    lips~lfimg    " Delivery Qty&lt;/P&gt;&lt;P&gt;    lips~kcmeng   " Cumulative Delivery Qty&lt;/P&gt;&lt;P&gt;    ltak~tanum    " TO #&lt;/P&gt;&lt;P&gt;    ltak~kquit    " TO Confirmed status&lt;/P&gt;&lt;P&gt;    ltak~druck    " TO Print Status&lt;/P&gt;&lt;P&gt;    vttk~tknum    " Shipment #&lt;/P&gt;&lt;P&gt;    vttk~dpabf    " Planned date for Shipment Completion&lt;/P&gt;&lt;P&gt;    vbfa_p~vbeln  " Proforma Invoice #&lt;/P&gt;&lt;P&gt;    vbfa_p~erdat  " Invoice Date&lt;/P&gt;&lt;P&gt;    INTO TABLE i_vbap_rob&lt;/P&gt;&lt;P&gt;    FROM  vbap&lt;/P&gt;&lt;P&gt;    JOIN  vbak ON   vbak&lt;SUB&gt;vbeln = vbap&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;    JOIN  kna1 ON   vbak&lt;SUB&gt;kunnr = kna1&lt;/SUB&gt;kunnr&lt;/P&gt;&lt;P&gt;    JOIN  vbfa ON   vbfa&lt;SUB&gt;vbelv = vbap&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;                  AND  vbfa&lt;SUB&gt;posnv = vbap&lt;/SUB&gt;posnr&lt;/P&gt;&lt;P&gt;    JOIN  lips ON   lips&lt;SUB&gt;vbeln = vbfa&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;                  AND  lips&lt;SUB&gt;posnr = vbfa&lt;/SUB&gt;posnn&lt;/P&gt;&lt;P&gt;    JOIN  ltak ON   ltak&lt;SUB&gt;vbeln = vbfa&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;    JOIN  vbfa AS   vbfa_s&lt;/P&gt;&lt;P&gt;                   ON   vbfa_s&lt;SUB&gt;vbelv = vbfa&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;    JOIN  vbfa AS   vbfa_p&lt;/P&gt;&lt;P&gt;                   ON   vbfa_p&lt;SUB&gt;vbelv = vbfa&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;                  AND  vbfa_p&lt;SUB&gt;posnv = vbfa&lt;/SUB&gt;posnn&lt;/P&gt;&lt;P&gt;    JOIN  vttk ON   vttk&lt;SUB&gt;tknum = vbfa_s&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;    JOIN  ltap ON   ltap&lt;SUB&gt;tanum = ltak&lt;/SUB&gt;tanum&lt;/P&gt;&lt;P&gt;    WHERE vbfa~vbtyp_n = 'J'&lt;/P&gt;&lt;P&gt;    AND ( vbfa~vbtyp_v = 'C'  " Regular Order&lt;/P&gt;&lt;P&gt;       OR vbfa~vbtyp_v = 'I' )" Sample Order&lt;/P&gt;&lt;P&gt;    AND   lips~fkrel = 'A'      " Select Deliveries relevant for Billing (in case split deliveries)&lt;/P&gt;&lt;P&gt;    AND   vbfa_s~vbtyp_n = '8'&lt;/P&gt;&lt;P&gt;    AND   vbfa_p~vbtyp_n = 'U'&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  In case there are multiple Porforma Inv., pick the latest copy.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    AND   vbfa_p&lt;SUB&gt;vbeln = ( SELECT  MAX( p&lt;/SUB&gt;vbeln )&lt;/P&gt;&lt;P&gt;                           FROM    vbfa AS p&lt;/P&gt;&lt;P&gt;                           WHERE   p&lt;SUB&gt;vbelv = vbfa&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;                           AND     p&lt;SUB&gt;posnv = vbfa&lt;/SUB&gt;posnn&lt;/P&gt;&lt;P&gt;                           AND     p~vbtyp_n = 'U'&lt;/P&gt;&lt;P&gt;                         )&lt;/P&gt;&lt;P&gt;    AND NOT EXISTS (  SELECT  * " exclude SO items with PGI &amp;amp; Billing&lt;/P&gt;&lt;P&gt;                      FROM    vbfa AS a&lt;/P&gt;&lt;P&gt;                      WHERE   a&lt;SUB&gt;vbelv = vbap&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;                      AND     a&lt;SUB&gt;posnv = vbap&lt;/SUB&gt;posnr&lt;/P&gt;&lt;P&gt;                      AND     ( a~vbtyp_n = 'R' OR  " exclude PGI&lt;/P&gt;&lt;P&gt;                                a~vbtyp_n = 'M'     " exclude Billing&lt;/P&gt;&lt;P&gt;                              )&lt;/P&gt;&lt;P&gt;                    )&lt;/P&gt;&lt;P&gt;    AND   ltak~kquit = 'X'&lt;/P&gt;&lt;P&gt;    AND   ltap~vdifm EQ 0             "SSR5465.n&lt;/P&gt;&lt;P&gt;    AND   vbak~kunnr IN s_kunnr&lt;/P&gt;&lt;P&gt;    AND   vbap~matnr IN s_matnr&lt;/P&gt;&lt;P&gt;    AND   vbap~vbeln IN s_vbeln&lt;/P&gt;&lt;P&gt;    AND   vbak~vkorg IN s_vkorg&lt;/P&gt;&lt;P&gt;    AND   vbap~lgort IN s_lgort&lt;/P&gt;&lt;P&gt;    AND   vttk~tknum IN s_ship&lt;/P&gt;&lt;P&gt;    AND   vttk~dpabf IN s_sdate&lt;/P&gt;&lt;P&gt;    AND   (cond_vtweg)&lt;/P&gt;&lt;P&gt;    AND   (cond_werks)&lt;/P&gt;&lt;P&gt;    ORDER BY vbap&lt;SUB&gt;vbeln vbap&lt;/SUB&gt;posnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     DELETE ADJACENT DUPLICATES FROM i_vbap_rob COMPARING ALL FIELDS.  "SSR5465.n&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2008 01:54:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385441#M812885</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-11T01:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Improve performance -  sql statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385442#M812886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi performance point of view, joining more tables is not preferred...and you are joining many tables... all you can do is to split the query into parts and use for all entires .. and obtain the output you wanted...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2008 02:26:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385442#M812886</guid>
      <dc:creator>former_member156446</dc:creator>
      <dc:date>2008-02-11T02:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Improve performance -  sql statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385443#M812887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you are using less number of tables then you can go for joins. Otherwise, better use FOR ALL ENTRIES statement. It would not have overload on the server. Everytime the data is fetched only from the internal tables except for the first time. I hope you understand. Get back if u still have queries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if useful. Best of luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2008 03:35:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385443#M812887</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-11T03:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Improve performance -  sql statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385444#M812888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Write the same prg.. using FOR ALL ENTRIES and observe the graph in SE30. U can find a lot of difference.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2008 03:36:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385444#M812888</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-11T03:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Improve performance -  sql statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385445#M812889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem is not with the number JOINs It is likely with the sub query or with not using proper indexes.&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, 11 Feb 2008 04:02:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385445#M812889</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-11T04:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Improve performance -  sql statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385446#M812890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you tell the incorrect usage of index?&lt;/P&gt;&lt;P&gt;..and can anyone elaborate more on using for all entries..?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2008 04:27:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385446#M812890</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-11T04:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Improve performance -  sql statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385447#M812891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would start over again and simplify.&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, 11 Feb 2008 14:52:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385447#M812891</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-11T14:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Improve performance -  sql statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385448#M812892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;performance point of u its better to use for all entries instead of using joins.using joins will take lot of time. And you can check the table entries available or not by using sy-dbcnt before for all entries in.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 May 2008 14:54:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385448#M812892</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-11T14:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: Improve performance -  sql statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385449#M812893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;gt; Hi,&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; I am still new to abap. Below is a simple sql that I hope to streamline, so that the performance could be improved. It has taken some amount of time to process. How can I improve the sql below? Thanks&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;What you have written is definitely not a simple sql; it is an extremely complicated bit of sql with far too many joins - 10 tables is it, not counting the subqueries, with VBFA joined to itself multiple times.  I use joins a lot - whatever anyone else says on this forum they can often be more efficient than the vastly overrated FOR ALL ENTRIES - but I would have doubts about joining more than about 6 tables unless I was really sure about what I was doing.  The more tables you join, the more time it takes the database optimizer to parse the statement to find the optimal access path.  And a very large join can be a support nightmare if it hasn't been carefully commented and needs to be maintained by one of the many Abapers who don't really do joins.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As already suggested, break it down and rewrite it as several statements, commenting each section so that anyone who has to maintain it has some idea what is going on.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The indexes on the joins etc look after a quick glance ok.  Using WHERE NOT EXISTS can be inefficient.  If you need to know about using FOR ALL ENTRIES, look it up in the SAP help or search for it here - it is a way of joining an ABAP internal table with a database table and can be very useful though it is not the solution to all efficiency problems.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 May 2008 16:09:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-performance-sql-statement/m-p/3385449#M812893</guid>
      <dc:creator>christine_evans</dc:creator>
      <dc:date>2008-05-11T16:09:32Z</dc:date>
    </item>
  </channel>
</rss>

