<?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 SUM statement efficiency in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441397#M209879</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to calculate some totals in an itab and have discivered the SUM statement, which seems a very easy way to achieve this.  However, being a cynical chap I was wondering if this carries a large overhead and will be less efficient than just storing a running total in a variable i.e x = x + y.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I anybody able to shed any light...?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 23 Jun 2006 11:49:52 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-06-23T11:49:52Z</dc:date>
    <item>
      <title>SUM statement efficiency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441397#M209879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to calculate some totals in an itab and have discivered the SUM statement, which seems a very easy way to achieve this.  However, being a cynical chap I was wondering if this carries a large overhead and will be less efficient than just storing a running total in a variable i.e x = x + y.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I anybody able to shed any light...?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Jun 2006 11:49:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441397#M209879</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-06-23T11:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: SUM statement efficiency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441398#M209880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SUM. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;When processing an internal table in a block starting with LOOP and concluded by ENDLOOP , SUM calculates the control totals of all fields of type I , F and P (see also ABAP/4 number types ) and places them in the LOOP output area (header line of the internal table or an explicitly specified work area). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sum statement in report is basically used in Control Break Processing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After you fill an internal table with data, you often need to write the data out. This output will frequently contain summary information(uch as totals) at the top or bottom of the report.There might also be interim situations (such as subtotals ) within the body of report.&lt;/P&gt;&lt;P&gt;To do this , you can read the data into an internal table and then, within loop at , use the following statements: &lt;/P&gt;&lt;P&gt;1. at first / endat&lt;/P&gt;&lt;P&gt;2.at last / endat&lt;/P&gt;&lt;P&gt;3.at new / endat&lt;/P&gt;&lt;P&gt;4.at end of / endat&lt;/P&gt;&lt;P&gt;5.sum&lt;/P&gt;&lt;P&gt;6.on change of / endon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first statement of each of these pairs - except for Sum - controls when the code lies between them is executed.This type of control is called a control break.Their purpose is to ececute the code between them whenever a specific condition in the data is detected during the processing of the loop. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using the Sum statement :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;syntax : &lt;/P&gt;&lt;P&gt;at first/last/new/end of.&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;sum&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;endat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where : &lt;/P&gt;&lt;P&gt;... represents any number of lines of code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sum calculates a total for the current value of the control level that contains it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It finds all rows that have the same values within the control level field and all fields of the left of it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It sums each numeric column to the right of the control level.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It places the totals in the corresponding fields of the work area.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Jun 2006 11:53:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441398#M209880</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-06-23T11:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: SUM statement efficiency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441399#M209881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kishan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for replying, however, I already know how the SUM statement works. I'm interested in whether or not this is the most efficient method of summing values in an itab - essentially whether:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT itab INTO wa.
SUM.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is more efficient than:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT itab INTO wa.
total = total + wa-value.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or vice versa.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does the size of the itab or other factors have any influence over which is better?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Jun 2006 13:25:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441399#M209881</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-06-23T13:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: SUM statement efficiency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441400#M209882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Refer foll links,&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/saphelp_46c/helpdata/en/fc/eb2ed0358411d1829f0000e829fbfe/frameset.htm" target="test_blank"&gt;http://help.sap.com/saphelp_46c/helpdata/en/fc/eb2ed0358411d1829f0000e829fbfe/frameset.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/saphelp_46c/helpdata/en/48/b4e449c0ca11d2a97100a0c9449261/frameset.htm" target="test_blank"&gt;http://help.sap.com/saphelp_46c/helpdata/en/48/b4e449c0ca11d2a97100a0c9449261/frameset.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please reward points.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Jun 2006 13:29:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441400#M209882</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-06-23T13:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: SUM statement efficiency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441401#M209883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi andrew,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. If its just a matter of totalling one or few&lt;/P&gt;&lt;P&gt;   fields of ther internal table,&lt;/P&gt;&lt;P&gt; then 2nd option will be more efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. BCOS&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. The first option involves CONTROL-BREAK PROCESSING (which is carried out internally)&lt;/P&gt;&lt;P&gt;(apart from the addition computation which it&lt;/P&gt;&lt;P&gt;does using SUM)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. The 2nd option is straight-forward &lt;/P&gt;&lt;P&gt;  arithmetic computation, which is always faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;amit m.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Jun 2006 13:31:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441401#M209883</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-06-23T13:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: SUM statement efficiency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441402#M209884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What I do when I want to know something like this is to simply write a small program that does lots of loop passes and compare the results. You can use " GET RUN TIME FIELD f" for the comparison.&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, 23 Jun 2006 13:35:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441402#M209884</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-06-23T13:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: SUM statement efficiency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441403#M209885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Andrew,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I assume that there are other uses for the internal table in your program and that you are not doing a SELECT just to be able to sum up the values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now here's what I would do - &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;1. I would prefer to use the SUM statement if there's only one numeric field in the internal table. Otherwise the other numeric fields will be summed up as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. In case option 1 fails , I do the summing manually.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. And lastly, I would see if I can directly do a COUNT( * ) from the database table if the number of entries is huge. I know that this would be an unconventional idea, but I have often found it to be performant.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anand Mandalika.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Jun 2006 13:39:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441403#M209885</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-06-23T13:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: SUM statement efficiency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441404#M209886</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;The keyword SUM should be used when we want to group the data and then find the sum of each group.&lt;/P&gt;&lt;P&gt;You can do this using AT NEW.... in the LOOP&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If sum of all the records is needed then '+' should be used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Depending upon the requirement you should decide to use SUM or '+'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sameena&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: sameena attarwala&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Jun 2006 13:39:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441404#M209886</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-06-23T13:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: SUM statement efficiency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441405#M209887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Amit&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, would I be correct in thinking that option two is better when control-break processing is not used but option 1 would be better when I am doing control-break processing?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Jun 2006 14:10:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441405#M209887</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-06-23T14:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: SUM statement efficiency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441406#M209888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. but option 1 would be better when I am doing control-break processing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes u are right.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. At the same time,&lt;/P&gt;&lt;P&gt;   even if there are 1000 to 1 lakh record,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   Loop at the internal table may take some time,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. but a simple arithmetic computation,&lt;/P&gt;&lt;P&gt;   in between this loop,&lt;/P&gt;&lt;P&gt;   will not affect performance noticeably.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  (it will almost be same as without the computation)&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;amit m.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Jun 2006 14:13:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-statement-efficiency/m-p/1441406#M209888</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-06-23T14:13:38Z</dc:date>
    </item>
  </channel>
</rss>

