<?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: Simple division question in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186262#M1980366</link>
    <description>&lt;P&gt;Sorry, I think I was not clear. I meant that if your type is defined like below (ebelp before ebeln, or any other type before ebeln), AT NEW vbeln won't work well at all because it would mean "at any change of ebelp or ebeln". That's just a well known error-prone aspect of AT NEW.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_essr,
      ebelp TYPE essr-ebelp, " not good to have something before ebeln
      ebeln TYPE essr-ebeln,
      netwr TYPE essr-netwr,
    END OF ty_essr.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;PS: I'm not talking about the SORT.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jun 2020 07:14:49 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2020-06-05T07:14:49Z</dc:date>
    <item>
      <title>Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186252#M1980356</link>
      <description>&lt;P&gt;I'm looking to divide the sum of line items for percentage. I have used at last &amp;amp; sum in a loop which provides the sum for each but having difficulty coding the division into a result. I've specified DATA: result TYPE p DECIMALS 2.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 14:24:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186252#M1980356</guid>
      <dc:creator>former_member559196</dc:creator>
      <dc:date>2020-06-04T14:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186253#M1980357</link>
      <description>&lt;P&gt;Hi Brian,&lt;/P&gt;&lt;P&gt;Please provide your code. It will be much easier to replicate your issue.&lt;/P&gt;&lt;P&gt;You're trying to calculate the percentage of what?&lt;/P&gt;Kind regards,&lt;BR /&gt;Mateusz</description>
      <pubDate>Thu, 04 Jun 2020 14:42:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186253#M1980357</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-06-04T14:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186254#M1980358</link>
      <description>&lt;P&gt;SUM is officially obsolete. AT LAST is almost obsolete.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 14:50:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186254#M1980358</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-06-04T14:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186255#M1980359</link>
      <description>&lt;P&gt;the ordered and delivered amount from me23n.&lt;/P&gt;&lt;P&gt;TABLES: essr, ekpo.&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF ty_essr,&lt;BR /&gt; ebeln TYPE essr-ebeln,&lt;BR /&gt; ebelp TYPE essr-ebelp,&lt;BR /&gt; netwr TYPE essr-netwr,&lt;BR /&gt; END OF ty_essr.&lt;BR /&gt;&lt;BR /&gt;DATA: wa_essr TYPE ty_essr,&lt;BR /&gt; it_essr TYPE TABLE OF ty_essr WITH HEADER LINE.&lt;BR /&gt;&lt;BR /&gt;TYPES: BEGIN OF ty_ekpo,&lt;BR /&gt; netpr TYPE ekpo-netpr,&lt;BR /&gt; END OF ty_ekpo.&lt;BR /&gt; &lt;BR /&gt;DATA: wa_ekpo TYPE ty_ekpo,&lt;BR /&gt; it_ekpo TYPE TABLE OF ty_ekpo WITH HEADER LINE.&lt;BR /&gt;&lt;BR /&gt;DATA: result TYPE p DECIMALS 2.&lt;BR /&gt;&lt;BR /&gt;INITIALIZATION.&lt;BR /&gt; SELECT-OPTIONS: s_ebeln FOR essr-ebeln.&lt;BR /&gt;&lt;BR /&gt;START-OF-SELECTION.&lt;BR /&gt; SELECT ebeln ebelp netwr&lt;BR /&gt; FROM essr INTO TABLE it_essr&lt;BR /&gt; WHERE ebeln IN s_ebeln.&lt;BR /&gt;&lt;BR /&gt; SELECT netpr&lt;BR /&gt; FROM ekpo INTO TABLE it_ekpo&lt;BR /&gt; WHERE ebeln IN s_ebeln.&lt;BR /&gt;&lt;BR /&gt; SORT it_essr.&lt;BR /&gt;&lt;BR /&gt; LOOP AT it_essr INTO wa_essr.&lt;BR /&gt; AT LAST.&lt;BR /&gt; SUM.&lt;BR /&gt; WRITE:&lt;BR /&gt; / 'ORDERED: ' COLOR 4,&lt;BR /&gt; 27 wa_essr-netwr.&lt;BR /&gt; ENDAT.&lt;BR /&gt; CLEAR: wa_essr.&lt;BR /&gt; ENDLOOP.&lt;BR /&gt;&lt;BR /&gt; LOOP AT it_ekpo INTO wa_ekpo.&lt;BR /&gt; AT LAST.&lt;BR /&gt; SUM.&lt;BR /&gt; WRITE:&lt;BR /&gt; / 'DELIVERED: ' COLOR 4,&lt;BR /&gt; 27 wa_ekpo-netpr.&lt;BR /&gt; ENDAT.&lt;BR /&gt; CLEAR: wa_ekpo.&lt;BR /&gt; ENDLOOP.&lt;BR /&gt;&lt;BR /&gt; WRITE: / 'Percent Complete: ' COLOR 5,&lt;BR /&gt; 19 result.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 14:56:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186255#M1980359</guid>
      <dc:creator>former_member559196</dc:creator>
      <dc:date>2020-06-04T14:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186256#M1980360</link>
      <description>&lt;P&gt;Hello Brian,&lt;/P&gt;&lt;P&gt;Answer option is for answer with the solution to the question. Better to use the "Comment" option.&lt;/P&gt;&lt;P&gt;Also, it would be nice if you put your code in the "Code" tag of the editor - for better readability.&lt;/P&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;Mateusz</description>
      <pubDate>Thu, 04 Jun 2020 15:00:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186256#M1980360</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-06-04T15:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186257#M1980361</link>
      <description>&lt;P&gt;Hello  &lt;SPAN class="mention-scrubbed"&gt;bcooper&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;To answer your issue - what you're doing is calculating and printing the sums, but you're not storing these anywhere. To be able to calculate the percentage you need to store the sums of each group and then calculate the percentage.&lt;/P&gt;&lt;P&gt;As far as I can see you're not using any conditions for the LOOP, so you're basically summing up all records. Correct?&lt;/P&gt;&lt;P&gt;If that's the case, then I'd propose you change your code as follows.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA:
  lv_essr_sum LIKE essr-netwr,
  lv_ekpo_sum LIKE ekpo-netwr.

SORT it_essr BY ebeln ebelp.
SORT it_ekpo BY ebeln.

LOOP AT it_essr INTO wa_essr.
  AT NEW ebeln.
    CLEAR:
      lv_essr_sum,
      lv_ekpo_sum.
  ENDAT.

  lv_essr_sum = lv_essr_sum + wa_essr-netwr.

  LOOP AT it_ekpo INTO wa_ekpo WHERE ebeln = wa_essr-ebeln.
    lv_ekpo_sum = lv_ekpo_sum + wa_ekpo-netpr.
  ENDLOOP.

  AT END OF ebeln.
    WRITE: / 'ORDERED: ' COLOR 4, 27 lv_essr_sum.
    WRITE: / 'DELIVERED: ' COLOR 4, 27 lv_ekpo_sum.

    IF lv_essr_sum &amp;gt; 0.
      result = ( lv_ekpo_sum * 100 ) / lv_essr_sum.
    ELSE.
      result = 0.
    ENDIF.

    WRITE: / 'Percent Complete: ' COLOR 5, 19 result.
  ENDAT.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;
Kind regards,&lt;BR /&gt;Mateusz</description>
      <pubDate>Thu, 04 Jun 2020 15:05:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186257#M1980361</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-06-04T15:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186258#M1980362</link>
      <description>&lt;P&gt;Actually, if this is the only thing that your report does, probably not, &lt;STRONG&gt;but if&lt;/STRONG&gt;, then you could sum the amounts in SQL and then skip the summing in LOOPs.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  SELECT ebeln, SUM( netwr ) AS netwr
    FROM essr
    INTO TABLE @DATA(it_essr)
    WHERE ebeln IN @s_ebeln
    GROUP BY ebeln.

  SELECT ebeln, SUM( netpr ) AS netpr
    FROM ekpo
    INTO TABLE @DATA(it_ekpo)
    WHERE ebeln IN @s_ebeln
    GROUP BY ebeln.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;Mateusz</description>
      <pubDate>Thu, 04 Jun 2020 15:19:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186258#M1980362</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-06-04T15:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186259#M1980363</link>
      <description>&lt;P&gt;Hi Mateusz&lt;/P&gt;&lt;P&gt;Thanks for the forum tips, I will use accordingly in future posts.  Also, you are correct, I'm looking to calculate and store the sum as this I was unable to do and yes, I'm taking the sum of all line items.  The code is part of a report but I do like sum amounts in SQL vs loops, very helpful.  Thanks for your time and assistance.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 20:29:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186259#M1980363</guid>
      <dc:creator>former_member559196</dc:creator>
      <dc:date>2020-06-04T20:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186260#M1980364</link>
      <description>&lt;P&gt;"LOOP AT it_essr ... AT NEW ebeln" will work well in all cases only if ebeln is at the first position of the line type, that's the case as per the definition given per Brian:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_essr,&lt;BR /&gt;      ebeln TYPE essr-ebeln,&lt;BR /&gt;      ebelp TYPE essr-ebelp,&lt;BR /&gt;      netwr TYPE essr-netwr,&lt;BR /&gt;    END OF ty_essr.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jun 2020 05:23:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186260#M1980364</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-06-05T05:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186261#M1980365</link>
      <description>&lt;P&gt;Hello  &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;That's not necessary true. If there were any WHERE conditions for the LOOP, there might be cases were the records are not selected in proper order thus making the AT NEW block not fire. Consider this simple example.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT *
  FROM vbap
  INTO TABLE @DATA(lt_vbap)
  UP TO 100 ROWS.

SORT lt_vbap BY vbeln posnr.
LOOP AT lt_vbap REFERENCE INTO DATA(ld_vbap)
  WHERE posnr = 20.

  AT NEW vbeln.
    WRITE: / ld_vbap-&amp;gt;vbeln.
  ENDAT.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this case the AT NEW vbeln block will never be executed, even though we can clearly see, that the VBELN value will change in sequence.&lt;/P&gt;&lt;P&gt;Reason for this is, I assume, that block firing places (so to speak) are defined on the internal table level, not on the LOOP level. From the &lt;A href="https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abapat_itab.htm"&gt;documentation&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Apart from the special variants AT FIRST and AT LAST, group levels are defined using the variant AT NEW and the sequence of rows in the internal table.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;The following rules must be followed for effective group level processing:&lt;/EM&gt;&lt;/P&gt;&lt;UL&gt;
&lt;LI&gt;&lt;EM&gt;A table key specified in LOOP in cond must be chosen so that it produces the required processing order of the imported rows.
&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;A restricting condition specified in LOOP in cond must select a contiguous row block in the internal table.&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Kind regards,&lt;/P&gt;Mateusz</description>
      <pubDate>Fri, 05 Jun 2020 06:28:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186261#M1980365</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-06-05T06:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186262#M1980366</link>
      <description>&lt;P&gt;Sorry, I think I was not clear. I meant that if your type is defined like below (ebelp before ebeln, or any other type before ebeln), AT NEW vbeln won't work well at all because it would mean "at any change of ebelp or ebeln". That's just a well known error-prone aspect of AT NEW.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_essr,
      ebelp TYPE essr-ebelp, " not good to have something before ebeln
      ebeln TYPE essr-ebeln,
      netwr TYPE essr-netwr,
    END OF ty_essr.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;PS: I'm not talking about the SORT.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 07:14:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186262#M1980366</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-06-05T07:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Simple division question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186263#M1980367</link>
      <description>&lt;P&gt;Yeap, that's right.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2020 07:35:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-division-question/m-p/12186263#M1980367</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-06-05T07:35:00Z</dc:date>
    </item>
  </channel>
</rss>

