<?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: Performance Issue in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465916#M219428</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;Some issus in the code:&lt;/P&gt;&lt;P&gt;a) avoid select inside loops&lt;/P&gt;&lt;P&gt;b) avoid using group by command and usm command while selecting, this you can do inside the code once you have finished will all the slect statement&lt;/P&gt;&lt;P&gt;b) try to use the full index for the tables&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this Helps&lt;/P&gt;&lt;P&gt;Anirban&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Aug 2006 05:37:09 GMT</pubDate>
    <dc:creator>former_member480923</dc:creator>
    <dc:date>2006-08-25T05:37:09Z</dc:date>
    <item>
      <title>Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465912#M219424</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 am facing a big performance issue in a abap program which produce the cash flow details our group of company. This is the logic I used to develop the report. (It is a SAP Script)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; - First I am getting the closed customer payment records from the table BSAD ( eg: - Type 'DZ') &lt;/P&gt;&lt;P&gt; - Then I am getting the corresponding invoices from the BSAD using the same BELNR ( eg :- Type &amp;lt;&amp;gt; 'DZ')&lt;/P&gt;&lt;P&gt; - Then checking the GL Entry (BSIS) for the corresponding records which select in the second stage.&lt;/P&gt;&lt;P&gt; - In a Z table I am keeping the account list by grouping   separate section ( Eg: - Customer receipts, fixed assets...etc).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have done the same thing to get the open item details also.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Report is correct and running perfectly, but my issue is it's taking long time to process. Because of this I made this report to run as a background job. But still it is taking such a long time. ( For Eg: - If 1000 records selected from the first stage, it will take about more than one hour to process, which is not good enough to run in a live environment)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pls advice me how to improve the performance of this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a code sample how to see how I have make the logic&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

   SELECT SUM( dmbtr ) AS dmbtr belnr kunnr hkont shkzg xblnr budat
blart bldat
   INTO CORRESPONDING FIELDS OF TABLE it_voucher3
   FROM  bsad
   WHERE   bukrs = p_bukrs AND gjahr = p_gjahr
           AND augdt IN s_bldat
           AND blart = 'DZ'
*            AND blart = 'DZ' and shkzg = 'S'

           GROUP BY kunnr belnr hkont shkzg xblnr budat blart bldat.

   SORT it_voucher3 BY kunnr.

   LOOP AT it_voucher3 INTO wa_voucher3.

* Select the invoices
     SELECT SUM( dmbtr ) AS dmbtr belnr kunnr hkont shkzg xblnr budat
blart bldat
     INTO CORRESPONDING FIELDS OF TABLE it_voucher1
     FROM  bsad
     WHERE   bukrs = p_bukrs AND gjahr = p_gjahr
             AND augdt IN s_bldat
             AND blart &amp;lt;&amp;gt; 'DZ' AND
             augbl = wa_voucher3-belnr AND
             kunnr = wa_voucher3-kunnr

             GROUP BY belnr kunnr hkont shkzg xblnr budat blart bldat.

     LOOP AT it_voucher1 INTO wa_voucher1.

*  Find the corresponding entry in the GL open
      SELECT SINGLE dmbtr FROM bsis INTO w_Rcptamt WHERE
*           hkont = '0010003900' AND
           hkont IN ( select fglacc from zcashflow_matrix WHERE FCODE =
'XX001' ) AND  bukrs = p_bukrs  AND
               gjahr = p_gjahr  AND
               belnr = wa_voucher1-belnr.

       IF sy-subrc &amp;lt;&amp;gt; 0.
* If the corresponding entry not found in GL open, look in the GL Closed
      SELECT SINGLE dmbtr FROM bsas INTO  w_Rcptamt  WHERE
           hkont IN ( select fglacc from zcashflow_matrix WHERE FCODE =
'XX001' ) AND bukrs = p_bukrs  AND
              gjahr = p_gjahr  AND
              belnr = wa_voucher1-belnr.

            IF sy-subrc = 0.
              w_Netamt = w_Netamt + w_Rcptamt.
              continue.
            ENDIF.
       ELSE.
             w_Netamt = w_Netamt + w_Rcptamt.
             continue.
       ENDIF.

************************************************************************
* Interest Income
      SELECT SINGLE dmbtr FROM bsis INTO w_IntIncomeAmt WHERE
           hkont IN ( select fglacc from zcashflow_matrix WHERE FCODE =
'XX002' ) AND  bukrs = p_bukrs  AND
               gjahr = p_gjahr  AND
               belnr = wa_voucher1-belnr.

       IF sy-subrc &amp;lt;&amp;gt; 0.
* If the corresponding entry not found in GL open, look in the GL Closed
      SELECT SINGLE dmbtr FROM bsas INTO  w_IntIncomeAmt  WHERE
           hkont IN ( select fglacc from zcashflow_matrix WHERE FCODE =
'XX002' ) AND bukrs = p_bukrs  AND
              gjahr = p_gjahr  AND
              belnr = wa_voucher1-belnr.

            IF sy-subrc = 0.
              w_IntIncome = w_IntIncome + w_IntIncomeAmt.
              continue.
            ENDIF.
       ELSE.
             w_IntIncome = w_IntIncome + w_IntIncomeAmt.
             continue.
       ENDIF.

************************************************************************

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Aug 2006 05:12:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465912#M219424</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-25T05:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465913#M219425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;avoid using SELECT statements in the loop&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to avoid that , first select all the entries into one internal table and then read this internal table in the loop&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and try to avoid INTO CORRESPONDING FIELDS also&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Aug 2006 05:15:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465913#M219425</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-25T05:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465914#M219426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try Use following Performance tools to resolve your problem..&lt;/P&gt;&lt;P&gt;1)SqlTrace(ST05)&lt;/P&gt;&lt;P&gt;2)Tips and trick tool&lt;/P&gt;&lt;P&gt;3)ABAP Runtime Analysis(SE30)&lt;/P&gt;&lt;P&gt;4)Code Inspector&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If helpful Reward Points&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Aug 2006 05:20:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465914#M219426</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-25T05:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465915#M219427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thanura,&lt;/P&gt;&lt;P&gt;Do not use SUM GROUP BY in select statement when your WHERE condition has many fields and you do have primary key fields.  Try to get maximum key fields if possible. &lt;/P&gt;&lt;P&gt;In stead use SELECT INTO TABLE AND then do SUM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do not use SELECT statement in LOOP.. ENDLOOP of internal table. Sort your itab on fields which will be used in WHERE CONDITION. Use SELECT .. FOR ALL ENTRIES IN ITAB  WHERE fld1 = ITAB-fld1 ..&lt;/P&gt;&lt;P&gt;After getting reuqired data in internal table use loop.. endloop and read table with key.. bainary search. For Binary search you need to sort the tables. Read more in ABAP help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this will give you pointers to improved performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please reward valuable replies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sunil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Aug 2006 05:24:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465915#M219427</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-25T05:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465916#M219428</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;Some issus in the code:&lt;/P&gt;&lt;P&gt;a) avoid select inside loops&lt;/P&gt;&lt;P&gt;b) avoid using group by command and usm command while selecting, this you can do inside the code once you have finished will all the slect statement&lt;/P&gt;&lt;P&gt;b) try to use the full index for the tables&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this Helps&lt;/P&gt;&lt;P&gt;Anirban&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Aug 2006 05:37:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465916#M219428</guid>
      <dc:creator>former_member480923</dc:creator>
      <dc:date>2006-08-25T05:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465917#M219429</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;Tks for the immidiate responce. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have used the select statement in the loop because, i want to get the GL entry for that particular invoice. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pls let me know a method how to avoid that select statement for the BSIS table from inside the loop. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As u all said is correct, if I use the select statement inside a loop , takes lot of time to execute. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pls let me know a method to avoid that BSIS selection from the loop&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Thanura&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Aug 2006 07:22:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465917#M219429</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-25T07:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465918#M219430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would suggest you try the below ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically separate your subquery ...so before the loop you can do the following..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select fglacc into ifglacc from zcashflow_matrix WHERE FCODE = 'XX001'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT it_voucher1 INTO wa_voucher1.&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; Find the corresponding entry in the GL open&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt; SELECT SINGLE hkont dmbtr  FROM bsis INTO w_hkont  w_Rcptamt WHERE&lt;/P&gt;&lt;P&gt; bukrs = p_bukrs  AND&lt;/P&gt;&lt;P&gt;            gjahr = p_gjahr  AND&lt;/P&gt;&lt;P&gt;               belnr = wa_voucher1-belnr.&lt;/P&gt;&lt;P&gt;  read table ifglacc with key fglacc = w_hkont.&lt;/P&gt;&lt;P&gt;  if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;  else.&lt;/P&gt;&lt;P&gt;  ---your other logic....&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;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Anurag Bankley&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Aug 2006 09:10:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465918#M219430</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-25T09:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465919#M219431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT SUM( dmbtr ) AS dmbtr belnr kunnr hkont shkzg xblnr budat
blart bldat
   INTO TABLE it_voucher3
   FROM  bsad
   WHERE   bukrs = p_bukrs AND 
           gjahr = p_gjahr AND
           augdt IN s_bldat AND 
            blart = 'DZ'.
if sy-subrc = 0.
  SORT it_voucher3 kunnr belnr 
                   hkont shkzg 
                   xblnr budat 
                    blart bldat .
endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;for this first SELECT from BSAD, i have few suggestions,&lt;/P&gt;&lt;P&gt;  1. do not use INTO CORRESPONDING FIELDS in  the SELECT. use the fields the order you define the internal table. else the system has to match each source and target fields if you use MOVE CORRESPONDING.&lt;/P&gt;&lt;P&gt;  2. DO not use GROUP BY , instead get all the data to your internal table and then use SORT with the fields, the way how you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2.&lt;/P&gt;&lt;P&gt;  instead of writing SELECT in the loop to fill it_voucher1 table ,use FOR ALL ENTRIES out side the loop and either use LOOP and ENDLOOP of it_voucher1 or use READ TABLE it_voucher1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;as below&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT SUM( dmbtr ) 
 AS dmbtr belnr kunnr hkont shkzg xblnr budat
    blart bldat
     INTO TABLE it_voucher1
     FROM  bsad
     FOR ALL ENTRIES OF &amp;lt;b&amp;gt;it_voucher3&amp;lt;/b&amp;gt; 
     WHERE   bukrs = p_bukrs AND gjahr = p_gjahr
             AND augdt IN s_bldat
             AND blart &amp;lt;&amp;gt; 'DZ' AND
             augbl = it_voucher3-belnr AND
             kunnr = it_voucher3-kunnr.
 Then use SORT 
  if sy-subrc = 0. 
   sort it_voucher1 BY belnr kunnr hkont shkzg xblnr budat blart bldat.
 endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but remember one thing if you are using FOR ALL ENTRIES, if the table you use with FOR ALL ENTRIES (in your case &lt;/P&gt;&lt;P&gt;it_voucher3) is EMPTY, then SELECT will FETCH ALL THE RECORDS. so first you check this it_voucher3 should not be empty.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT it_voucher3 INTO wa_voucher3.

 LOOP AT it_voucher1 INTO wa_voucher1 where augbl = wa_voucher3-belnr 
                                            kunnr = wa_voucher3-kunnr.

  like this you can avoid SELECT in LOOPs and also you can use READ TABLE instead
 ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;srikanth&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Srikanth Kidambi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Aug 2006 09:26:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue/m-p/1465919#M219431</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-25T09:26:34Z</dc:date>
    </item>
  </channel>
</rss>

