<?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: Hi CPU usage in ABAP coding in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666969#M1288742</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;use internal table  of type sorted&lt;/P&gt;&lt;P&gt; for your loop that will reduce cpu usage &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Alpesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Jun 2009 08:43:46 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-06-05T08:43:46Z</dc:date>
    <item>
      <title>Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666968#M1288741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a custom program (programmed by somebody else) which is churning away all day long and consuming between 50% and 70% CPU as seen in the 'top' command. I'm on HP-UX with 8 CPUs installed. The CPU usage is consistently at this level. (I matched the PID from SM50 with the PID in 'top')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ran abap traces in ST12 which found that between 60% and 70% of the time was spent in the following coding:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;773	  IF SY-SUBRC &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;774	    LOOP AT GIT_ZTABLEA TRANSPORTING NO FIELDS&lt;/P&gt;&lt;P&gt;775	      WHERE KUNNR      =  PC_KUNNR     "CUSTOMER CODEﾞ&lt;/P&gt;&lt;P&gt;776	        AND ZZVCGRTNFG IN P_DRTNFG     "FLAGﾞ(SELECTION CRITEREA)&lt;/P&gt;&lt;P&gt;777	        AND ZZVCGSTPFG IN P_DSPDFG .   "QUIT FLAGﾞ(SELECTION CRITEREA)&lt;/P&gt;&lt;P&gt;778	      EXIT.&lt;/P&gt;&lt;P&gt;779	    ENDLOOP .&lt;/P&gt;&lt;P&gt;780                                                                                &lt;/P&gt;&lt;P&gt;781	*   &lt;/P&gt;&lt;P&gt;782	    PI_SUBRC = SY-SUBRC .&lt;/P&gt;&lt;P&gt;783	    RETURN .&lt;/P&gt;&lt;P&gt;784                                                                                &lt;/P&gt;&lt;P&gt;785	*&lt;/P&gt;&lt;P&gt;786	  ELSE.&lt;/P&gt;&lt;P&gt;787	    LOOP AT GIT_ZTABLEA TRANSPORTING NO FIELDS&lt;/P&gt;&lt;P&gt;788	      WHERE ZZVCGGRPID =  GFC_TABLEB-ZZVCGGRPID "GROUP ID&lt;/P&gt;&lt;P&gt;789	        AND ZZVCGRTNFG IN P_DRTNFG               "FLAGﾞ(SELECTION CRITEREA)&lt;/P&gt;&lt;P&gt;790	        AND ZZVCGSTPFG IN P_DSPDFG.              "STOP FLAGﾞ(SELECTION CRITEREA)&lt;/P&gt;&lt;P&gt;791	      EXIT.&lt;/P&gt;&lt;P&gt;792	    ENDLOOP .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess the idea here is to just find the number of rows in GIT_ZTABLEA for certain conditions.&lt;/P&gt;&lt;P&gt;Is there a simple and less intensive way of achieving this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(apologies in advance for foreseen dumb questions. I'm very new to coding).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2009 08:28:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666968#M1288741</guid>
      <dc:creator>peter_strauss</dc:creator>
      <dc:date>2009-06-05T08:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666969#M1288742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;use internal table  of type sorted&lt;/P&gt;&lt;P&gt; for your loop that will reduce cpu usage &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Alpesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2009 08:43:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666969#M1288742</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-05T08:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666970#M1288743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; LOOP AT GIT_ZTABLEA TRANSPORTING NO FIELDS&lt;/P&gt;&lt;P&gt;&amp;gt; 775 WHERE KUNNR = PC_KUNNR "CUSTOMER CODEﾞ&lt;/P&gt;&lt;P&gt;&amp;gt; 776 AND ZZVCGRTNFG IN P_DRTNFG "FLAGﾞ(SELECTION CRITEREA)&lt;/P&gt;&lt;P&gt;&amp;gt; 777 AND ZZVCGSTPFG IN P_DSPDFG . "QUIT FLAGﾞ(SELECTION CRITEREA)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sorted table ... is the usual answer but not in this case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should check the IN P_DRTNFG "FLAGﾞ(SELECTION CRITEREA) ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What does it mean? I don`t undterstand the flag.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With the IN conditions I doubt that there is any optimziation possible, it will always scan.&lt;/P&gt;&lt;P&gt;If the two IN-flag are really flags then it should be possible to write equal condition&lt;/P&gt;&lt;P&gt;and get something &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  WHERE k = a AND z1 = b AND z2 = c.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The can be solved with sorted tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And from the coding you show with will exit after the first solution, so a READ would then also&lt;/P&gt;&lt;P&gt;be enough. The LOOP is only used because the WHERE is only possible with the LOOP.&lt;/P&gt;&lt;P&gt;but a LOOP is not really necessary because it check only the first solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So please revise the logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then it will become really fast.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2009 13:03:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666970#M1288743</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-05T13:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666971#M1288744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is this code called from within a loop or is it in a form called from within a loop?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2009 13:26:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666971#M1288744</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-05T13:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666972#M1288745</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 a bit confused about the IN statements. The fields are describes as Flag, a flag is usually yes or no why using an in statement there?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Furthermore sorting the table could add to performance if the table is sorted by customer code as sorted tables look for the start dataset in binary search when the key or a key part is specified.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rgds.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Roman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Jun 2009 23:01:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666972#M1288745</guid>
      <dc:creator>romanweise</dc:creator>
      <dc:date>2009-06-06T23:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666973#M1288746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;that is the more general case of a often repeated recommendation.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
sort GIT_ZTABLEA by ZZVCGGRPID.
....

read table GIT_ZTABLEA transporting no fields  
                  with key ZZVCGGRPID = GFC_TABLEB-ZZVCGGRPID.

IDX = SY-TABIX.

loop at GIT_ZTABLEA into WA from index IDX   

   if (        WA-ZZVCGGRPID = GFC_TABLEB-ZZVCGGRPID 
        and WA-ZZVCGRTNFG IN P_DRTNFG
        and  WA-ZZVCGSTPFG IN P_DSPDFG ). 
*  success  -&amp;gt; exit ???
   endif.

   if not ( WA-ZZVCGGRPID = GFC_TABLEB-ZZVCGGRPID.
      exit.
   endif.
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;there is something missing, in your posting, you don't discriminate between the cae where something is found and nothing is found&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Jun 2009 15:32:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666973#M1288746</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-07T15:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666974#M1288747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you can replace the above code like this but the thing is i dont see you keeping any record with any of these loops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data: lv_index1 type  sy-index,
        lv_index2 type sy-index.

sort GIT_ZTABLEA by KUNNR ZZVCGRTNFG ZZVCGSTPFG

loop at GIT_ZTABLEA from lv_index1.

if GIT_ZTABLEA-KUNNR = PC_KUNNR or  ZZVCGRTNFG in GIT_ZTABLEA  or ZZVCGSTPFG in GIT_ZTABLEA.
lv_index1 = sy-index.
exit.
endif.

endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nafran.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 05:43:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666974#M1288747</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T05:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666975#M1288748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; you can replace the above code like this but &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;no, he can't oyur solution is simply wrong!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 06:37:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666975#M1288748</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T06:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666976#M1288749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ya both your and my code is wrong i guess coz even in yours the index is not updated and after looking at the main code again i think this will be the correct  code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data: lv_index1 type  sy-index,
        lv_index2 type sy-index.
 
sort GIT_ZTABLEA by KUNNR ZZVCGRTNFG ZZVCGSTPFG

loop at GIT_ZTABLEA from lv_index1.
 
if ( GIT_ZTABLEA-KUNNR = PC_KUNNR and  ZZVCGRTNFG in GIT_ZTABLEA  and ZZVCGSTPFG in GIT_ZTABLEA. )
lv_index1 = sy-index.
exit.

endif.
 
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 08:45:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666976#M1288749</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T08:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666977#M1288750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; ya both your and my code is wrong i guess coz even in yours the index is not updated and &lt;/P&gt;&lt;P&gt;&amp;gt; after looking at the main code again i think this will be the correct code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;nonsense, my code is correct, while yours is still wrong &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You aussume that both tables are sorted in the same way and that both contain the same keys,&lt;/P&gt;&lt;P&gt;both anssumptions are wrong! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If a record is missing then you will never determine a new index!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The READ BINARY SEARCH determines the index, and that is the main point of the optimization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please think twice before you want to correct me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 10:11:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666977#M1288750</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T10:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Hi CPU usage in ABAP coding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666978#M1288751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all. Even the "not so good" advice has been great.&lt;/P&gt;&lt;P&gt;It's good to know that the code does have room for improvement; it will take me some time to understand all the advice however I got exactly what I was looking for.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 10:46:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hi-cpu-usage-in-abap-coding/m-p/5666978#M1288751</guid>
      <dc:creator>peter_strauss</dc:creator>
      <dc:date>2009-06-08T10:46:48Z</dc:date>
    </item>
  </channel>
</rss>

