<?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: average calculation for different rows in one internal table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737094#M35016</link>
    <description>&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;cause I don't have this functionalities tow or I don't know if more date should be declared ,I have written the code below, somehow and although there are different materials numbers the count is always = 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT lt_show_avg_final INTO ls_show_avg_final 

  AT NEW acctg_spec_id.

    CLEAR count.

  ENDAT.

  ADD 1 TO count.



  CASE count.



    WHEN 1.



      APPEND ls_show_avg_final TO lt_output .

    WHEN 2.

     ls_show_avg_final-avg_expns = (  ls_show_avg_final-avg_expns + ls_show_avg_final-expns ) / 2.

      APPEND  ls_show_avg_final TO lt_output .

  ENDCASE.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;in this  case, I  had at the end the same table &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lt_show_avg_final = lt_output.&lt;/P&gt;&lt;P&gt;your help is really much appreciated,&lt;BR /&gt;&lt;BR /&gt;Best Regards&lt;BR /&gt;&lt;BR /&gt;Jenie&lt;/P&gt;</description>
    <pubDate>Tue, 30 Oct 2018 11:02:39 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2018-10-30T11:02:39Z</dc:date>
    <item>
      <title>average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737089#M35011</link>
      <description>&lt;P&gt;Hello Experts,&lt;BR /&gt;I have a requirement to calculate the average of sales values for different materials&lt;BR /&gt;to do this I have gathered all the data in an internal Table which has flowing columns and rows:&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; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;STRONG&gt;Material number, sales value ,Priods &lt;/STRONG&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;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;10000, 500 ,2018.6 &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; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;10000 ,600 ,2018.7&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; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; 10000 ,400, 2018.8&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; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; 10001 ,10000, 2018.8 &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;10001, 9500 ,2018.7 10002 532 2018.8 &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; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;* Now I am trying to calculate the average sales vlaues for the last two periods for each material number.&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; &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; &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; &lt;/P&gt;
  &lt;P&gt;To do this I have coded as below :&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; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;LOOP AT lt_show_avg INTO ls_show_avg.
  COLLECT  ls_show_avg INTO lt_show_avg_final .
ENDLOOP.
**********************************************************************

SORT lt_show_avg_final BY  MATNR priod DESCENDING.
**********************************************************************
* here the problem will start
LOOP AT lt_show_avg_final INTO ls_show_avg_final . 
  ADD 1 TO lv_count.
  IF lv_count &amp;gt; 2.
    DELETE lt_show_avg_final.

  ENDIF.
ENDLOOP.
*--------------------------------------------------------------------*

LOOP AT lt_show_avg_final INTO ls_show_avg_final.
  CLEAR ls_show_avg_final.
  ADD 1 TO lv_count_final.
  AT LAST.
    SUM.
    lv_total_expns = ls_show_avg_final-expns.
    lv_avg_expns = lv_total_expns  / lv_count_final.
  ENDAT.
APPEND ls_show_avg_final to lt_show_avg_final
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&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; &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; &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; &lt;/P&gt;
  &lt;P&gt;everything is ok when I am trying with one material number, but when I am entering many numbers then the problem will appear, cause I will read just the first two rows and all the calculation process will go further wrongly.&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; &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; &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; &lt;/P&gt;
  &lt;P&gt;What I want to show is as the follwing &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; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;* Priods are not necessary to be shown anymore&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; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;STRONG&gt;Material number, sales value, Priods, Sales Average&lt;/STRONG&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;
  &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;
  &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;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;10000 ,1100 ,2018.8 +2018.7 ,550&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; &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; &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; &lt;/P&gt;
  &lt;P&gt;10001 ,19500, 2018.8+2018.7 ,9750&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; &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; &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; &lt;/P&gt;
  &lt;P&gt;10002 ,532 ,2018.8 ,532&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; &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; &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; &lt;/P&gt;
  &lt;P&gt;Could you please help to achieve this?&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; &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; &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; &lt;/P&gt;
  &lt;P&gt; Best Regards&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; &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; &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; &lt;/P&gt;
  &lt;P&gt;Jenie&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; &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; &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; &lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 11:20:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737089#M35011</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-26T11:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737090#M35012</link>
      <description>&lt;P&gt;It's more a matter of pure logic than ABAP &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You already ordered your table and this is good: now ask yourself, why it works with one material and not with multiple ones?&lt;BR /&gt;The reason is the statement you are using "AT LAST", which works on the VERY LAST RECORD of your internal table, regardless any other sortering nor condition.&lt;/P&gt;&lt;P&gt;To fix your problem, you have to use AT NEW ... and AT END OF .....  and, keeping your table ordered, you can "break" when you want (i.e. obtaining subtotals for material AND period).&lt;/P&gt;&lt;P&gt;Try to use them and let us know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 16:15:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737090#M35012</guid>
      <dc:creator>SimoneMilesi</dc:creator>
      <dc:date>2018-10-26T16:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737091#M35013</link>
      <description>&lt;P&gt;Hi Jenie,&lt;/P&gt;&lt;P&gt;I think using the break is a good idea. Maybe this is a way how things could have been done?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;    DATA count TYPE i.
    SORT lt_tab BY matnr period DESCENDING.
    LOOP AT lt_tab INTO DATA(ls_row). 
      AT NEW matnr.
        CLEAR count.
      ENDAT.
      ADD 1 TO count.
      CASE count.
        WHEN 1.
          APPEND ls_row TO r_result REFERENCE INTO DATA(lr_result_row).
        WHEN 2.
          "lr_result_row-&amp;gt;* = VALUE #(  BASE lr_result_row-&amp;gt;*
          "    period = |{ lr_result_row-&amp;gt;period } + { ls_row-period }|
          "    price = ( lr_result_row-&amp;gt;price + ls_row-price ) / 2
          ").
          lr_result_row-&amp;gt;period = |{ lr_result_row-&amp;gt;period } + { ls_row-period }|.
          lr_result_row-&amp;gt;price  = ( lr_result_row-&amp;gt;price + ls_row-price ) / 2.
      ENDCASE.
    ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 06:15:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737091#M35013</guid>
      <dc:creator>pjl</dc:creator>
      <dc:date>2018-10-27T06:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737092#M35014</link>
      <description>&lt;P&gt;Many thanks Peter I will try and come back :). But my ABAP is not supporting  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;VALUE#(BASE


**what do I do in this case ?

Best Regards&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 09:14:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737092#M35014</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-30T09:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737093#M35015</link>
      <description>&lt;P&gt;I updated my code by using less lines and maybe closer to your ABAP Version. You should have statet btw, that your ABAP is below 740.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 10:11:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737093#M35015</guid>
      <dc:creator>pjl</dc:creator>
      <dc:date>2018-10-30T10:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737094#M35016</link>
      <description>&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;cause I don't have this functionalities tow or I don't know if more date should be declared ,I have written the code below, somehow and although there are different materials numbers the count is always = 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT lt_show_avg_final INTO ls_show_avg_final 

  AT NEW acctg_spec_id.

    CLEAR count.

  ENDAT.

  ADD 1 TO count.



  CASE count.



    WHEN 1.



      APPEND ls_show_avg_final TO lt_output .

    WHEN 2.

     ls_show_avg_final-avg_expns = (  ls_show_avg_final-avg_expns + ls_show_avg_final-expns ) / 2.

      APPEND  ls_show_avg_final TO lt_output .

  ENDCASE.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;in this  case, I  had at the end the same table &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lt_show_avg_final = lt_output.&lt;/P&gt;&lt;P&gt;your help is really much appreciated,&lt;BR /&gt;&lt;BR /&gt;Best Regards&lt;BR /&gt;&lt;BR /&gt;Jenie&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 11:02:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737094#M35016</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-30T11:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737095#M35017</link>
      <description>&lt;P&gt;Hi Jenie,&lt;/P&gt;&lt;P&gt;my questions in the code below...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT lt_show_avg_final INTO ls_show_avg_final 
  AT NEW acctg_spec_id. " assuming your table is ordered by this field if not, this will not work
    CLEAR count.
  ENDAT.
  ADD 1 TO count.
  CASE count.
    WHEN 1. " first line just copied
      APPEND ls_show_avg_final TO lt_output .  " is the avg_expns = expns ? If not you should do so here&lt;BR /&gt;      " as well you should keep a reference or a field symbol referring to this specific line.
    WHEN 2.&lt;BR /&gt;     " this doesnt make any sense, since you want to refer to the first line, which is not in scopy anymore
     " if you had a field symbol you could do something like &amp;lt;fs&amp;gt;-avg_expns = &amp;lt;fs&amp;gt;-avg_expns + ls_show_avg_final-expns ) / 2.
     ls_show_avg_final-avg_expns = (  ls_show_avg_final-avg_expns + ls_show_avg_final-expns ) / 2.
      APPEND  ls_show_avg_final TO lt_output . " don't do an append here, since you dont want a second &lt;BR /&gt;      " line in your output. You need to modify the first line with the new average. That's why you need&lt;BR /&gt;      " something like a reference, what I used or a field symbol.
  ENDCASE.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 13:25:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737095#M35017</guid>
      <dc:creator>pjl</dc:creator>
      <dc:date>2018-10-30T13:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737096#M35018</link>
      <description>&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks for your feedback, please find below my Input.,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOPAT lt_show_avg_final INTO ls_show_avg_final 
  AT NEW MATNR." this was typing mastik, sorrx for that.

CLEAR count.

ENDAT.

ADD 1 TO count.

CASE count.

WHEN 1." first line just copied

APPEND ls_show_avg_final TO lt_output ." is the avg_expns = expns ? If not you should do so here&lt;BR /&gt;" as well you should keep a reference or a field symbol referring to this specific line
I agree with you but could show me how this can be done as the first line has no  Avg and REFERENCE INTO DATA(lr_result_row) is not working with my ABAP version.

WHEN2.&lt;BR /&gt;" this doesnt make any sense, since you want to refer to the first line, which is not in scopy anymore" if you had a field symbol you could do something like &amp;lt;fs&amp;gt;-avg_expns = &amp;lt;fs&amp;gt;-avg_expns + ls_show_avg_final-expns ) / 2.
     ls_show_avg_final-avg_expns =(  ls_show_avg_final-avg_expns + ls_show_avg_final-expns )/2.

APPEND  ls_show_avg_final TO lt_output ." don't do an append here, since you dont want a second &lt;BR /&gt;" line in your output. You need to modify the first line with the new average. That's why you need&lt;BR /&gt;" something like a reference, what I used or a field symbol.

ENDCASE.

one more Questions what is the type or the definition of lr_result_row.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;P&gt;Jenie&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 15:07:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737096#M35018</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-30T15:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737097#M35019</link>
      <description>&lt;P&gt;Hi Jenie,&lt;/P&gt;&lt;P&gt;as for the structure, I have none defined. You're the one who has some structure to fill. So tell us. Especially you need to define if the input and output table structures are same or not. And if not, you need to tell us both structure definitions. Than its easier to point out.&lt;/P&gt;&lt;P&gt;And for the inline declaration, this can always be solved by a typical FIELD-SYMBOLS declaration somewhere in the front of your program. This should be declared as the line type of your output table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 17:12:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737097#M35019</guid>
      <dc:creator>pjl</dc:creator>
      <dc:date>2018-10-30T17:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737098#M35020</link>
      <description>&lt;P&gt;Hi Peter ,&lt;BR /&gt;&lt;BR /&gt;Many thanks for your input, the Problem that now has appeared is when I have for some materials numbers one Priode then the avg. will be zero in this case.&lt;/P&gt;&lt;P&gt;Do you have any idea to solve this?&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;P&gt;Jenie&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 18:57:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737098#M35020</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-30T18:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737099#M35021</link>
      <description>&lt;P&gt;Furhter more regarding this Point ,&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;is the avg_expns = expns ? If not you should do so here&lt;BR /&gt;" as well you should keep a reference or a field symbol referring to this specific line.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;could you please tell how exactly can this be done as my output structure is very simple,&lt;/P&gt;&lt;P&gt;Types begin of ts_output.&lt;/P&gt;&lt;P&gt;types Priod type zpriod&lt;/P&gt;&lt;P&gt;types matnr type matnr&lt;/P&gt;&lt;P&gt;types sales txpe zsales&lt;/P&gt;&lt;P&gt;endof ts_output.&lt;/P&gt;&lt;P&gt;data ls_output type ts_output.&lt;/P&gt;&lt;P&gt;data lt_output type standerd table of ts_output.&lt;/P&gt;&lt;P&gt;fiels-symblos &amp;lt;ls_output&amp;gt;  like line of lt_output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 19:07:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737099#M35021</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-30T19:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: average calculation for different rows in one internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737100#M35022</link>
      <description>&lt;P&gt;Hi Simone,&lt;/P&gt;&lt;P&gt;Thank your for your Input..&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;P&gt;Jenie&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 21:51:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/average-calculation-for-different-rows-in-one-internal-table/m-p/737100#M35022</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-30T21:51:29Z</dc:date>
    </item>
  </channel>
</rss>

