<?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: Query Optimization in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932268#M61109</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Instead of doing a SUM on the database table, it would be better to do a COLLECT on i_data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT i_data.
    SELECT a~fkimg FROM vbrp AS a
             INNER JOIN vbrk AS b 
                     ON a~vbeln = b~vbeln
                   INTO i_data-fkimg
                  WHERE a~aubel = i_data-vbeln 
                    AND a~aupos = i_data-posnr 
                    AND b~fksto = ' ' 
                    AND b~vbtyp = 'M'.
    COLLECT i_data. "assuming i_data has no other numeric fields.
ENDLOOP.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Srinivas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 12 Sep 2005 03:41:10 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-09-12T03:41:10Z</dc:date>
    <item>
      <title>Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932267#M61108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;i have a report which is very slow after analysing it the following querys is making the report very slow,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if any body can tell me how to optimize the following query...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; LOOP AT i_data.
    SELECT SUM( a~fkimg )
     FROM vbrp AS a
       INNER JOIN vbrk AS b ON
        a~vbeln = b~vbeln
      INTO i_data-fkimg
     WHERE a~aubel = i_data-vbeln AND
           a~aupos = i_data-posnr AND
           b~fksto = ' ' AND
           b~vbtyp = 'M'.
  ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanx&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;abhishek suppal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Sep 2005 03:34:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932267#M61108</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-12T03:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932268#M61109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Instead of doing a SUM on the database table, it would be better to do a COLLECT on i_data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT i_data.
    SELECT a~fkimg FROM vbrp AS a
             INNER JOIN vbrk AS b 
                     ON a~vbeln = b~vbeln
                   INTO i_data-fkimg
                  WHERE a~aubel = i_data-vbeln 
                    AND a~aupos = i_data-posnr 
                    AND b~fksto = ' ' 
                    AND b~vbtyp = 'M'.
    COLLECT i_data. "assuming i_data has no other numeric fields.
ENDLOOP.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Srinivas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Sep 2005 03:41:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932268#M61109</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-12T03:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932269#M61110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Abhishek.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Doing a select within a loop is going to be costly.&lt;/P&gt;&lt;P&gt;Moreover, the first selection has to be from vbrk and not vbrp... &lt;/P&gt;&lt;P&gt;Try this code...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:&lt;/P&gt;&lt;P&gt;  begin of tab occurs 0,&lt;/P&gt;&lt;P&gt;    vbeln type vbeln,&lt;/P&gt;&lt;P&gt;    posnr type posnr,&lt;/P&gt;&lt;P&gt;    fkimg type vbrp-fkimg,&lt;/P&gt;&lt;P&gt;  end of tab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if i_data[] is not initial.&lt;/P&gt;&lt;P&gt;  SELECT a~fkimg&lt;/P&gt;&lt;P&gt;  FROM vbrk AS b&lt;/P&gt;&lt;P&gt;  INNER JOIN vbrp AS a ON a&lt;SUB&gt;vbeln = b&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;  INTO table tab&lt;/P&gt;&lt;P&gt;  for all entries in i_data&lt;/P&gt;&lt;P&gt;  WHERE a~aubel = i_data-vbeln &lt;/P&gt;&lt;P&gt;  AND a~aupos = i_data-posnr &lt;/P&gt;&lt;P&gt;  AND b~fksto = ' ' &lt;/P&gt;&lt;P&gt;  AND b~vbtyp = 'M'.&lt;/P&gt;&lt;P&gt;endif.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tab will have document/item and qty.&lt;/P&gt;&lt;P&gt;You can sum this and put it back into i_data.&lt;/P&gt;&lt;P&gt;You can not use for all entries with sum and hence  you need to do it this way.&lt;/P&gt;&lt;P&gt;I am sure this will be a lot of performance optimization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tyr adn let me know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S&amp;gt; Remember to reward points and close this post if this solves ur problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rgds,&lt;/P&gt;&lt;P&gt;Prash.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Sep 2005 03:55:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932269#M61110</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-12T03:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932270#M61111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Abishek,&lt;/P&gt;&lt;P&gt;     You can sort based on the required field and delete adjacent duplicates and then put it in a loop.This can improve performance considerably.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Latha Prabhu.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Sep 2005 04:02:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932270#M61111</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-12T04:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932271#M61112</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 with this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : i_data1 like vbrp-fkimg occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort i_data by vbeln posnr.&lt;/P&gt;&lt;P&gt;delete adjacent duplicates from i_data comparing vbeln posnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if not i_data[] is initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   SELECT b~fkimg INTO table i_data1&lt;/P&gt;&lt;P&gt;          FROM vbrk AS a&lt;/P&gt;&lt;P&gt;          INNER JOIN vbrp AS b ON&lt;/P&gt;&lt;P&gt;          a&lt;SUB&gt;vbeln = b&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;          for all entries in i_data&lt;/P&gt;&lt;P&gt;          WHERE&lt;/P&gt;&lt;P&gt;          a~fksto = ' ' AND&lt;/P&gt;&lt;P&gt;          a~vbtyp = 'M' and&lt;/P&gt;&lt;P&gt;          b~aubel = i_data-vbeln AND&lt;/P&gt;&lt;P&gt;          b~aupos = i_data-posnr.&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;if i_data1[] is not initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;do the sum in i_data1&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Sasi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Sep 2005 04:33:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932271#M61112</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-12T04:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932272#M61113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Abi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Firstly, there is a mistake in the code that you have posted. After you select the sum ( a~fkimg ) into i_data-fkimg you are not modifying the table i_data. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming that it was typo.&lt;/P&gt;&lt;P&gt;My solution is use select endselect instead of writing code to first select from vbak,vbap and then select from vbrk, vbrp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try this one out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * UP TO 10 ROWS FROM VBAP.&lt;/P&gt;&lt;P&gt;          SELECT B~fkimg  FROM vbrK AS a&lt;/P&gt;&lt;P&gt;                        INNER JOIN vbrP AS b&lt;/P&gt;&lt;P&gt;                        ON a&lt;SUB&gt;vbeln = b&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;                        INTO V_fkimg&lt;/P&gt;&lt;P&gt;                        WHERE B~aubel = VBAP-vbeln AND&lt;/P&gt;&lt;P&gt;                              B~aupos = VBAP-posnr AND&lt;/P&gt;&lt;P&gt;                              A~fksto = ' ' AND&lt;/P&gt;&lt;P&gt;                              A~vbtyp = 'M'.&lt;/P&gt;&lt;P&gt;IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt; TAB-FKIMG = TAB-FKIMG + V_FKIMG.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;TAB-VBELN = VBAP-VBELN.&lt;/P&gt;&lt;P&gt;TAB-POSNR = VBAP-POSNR.&lt;/P&gt;&lt;P&gt;APPEND TAB.&lt;/P&gt;&lt;P&gt;CLEAR TAB.&lt;/P&gt;&lt;P&gt;CLEAR V_FKIMG.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and let me know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bye,&lt;/P&gt;&lt;P&gt;SAP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Sep 2005 05:10:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932272#M61113</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-12T05:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932273#M61114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanx all for ur replies any ways the solutions u have give are correct one, i have tried thes, but still its slow, is there no other query from which i can find the Sale Order and Billing document Link, acessing vbrp table takes lot of time. is there any other link by which i can know the Billing document no. against the Sale Order. if so then tell me..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;abhishek suppal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Sep 2005 06:50:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932273#M61114</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-12T06:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932274#M61115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Abhi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try using table VBFA. This is the document flow. It will show the relationships between the Sales DOcuments.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Enter in your Sales Order Number into VBELV and make sure VBTYP_N = 'M' and VBTYP_N = 'C'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CHeers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS. Kindly assign Reward Points to the posts you find helpful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Sep 2005 07:05:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932274#M61115</guid>
      <dc:creator>former_member221770</dc:creator>
      <dc:date>2005-09-12T07:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Query Optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932275#M61116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanx Pat,&lt;/P&gt;&lt;P&gt;it solved the problem...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;abhishek suppal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2005 03:57:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/932275#M61116</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-13T03:57:39Z</dc:date>
    </item>
  </channel>
</rss>

