<?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: Using REDUCE to Sum a Table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536193#M2005813</link>
    <description>&lt;P&gt;Here is a &lt;A href="https://github.com/AndreaBorgia-Abo/ABAP-Examples/blob/main/src/video/zabo_reduce_operator.prog.abap" target="_blank"&gt;complete working example&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Mar 2022 18:28:44 GMT</pubDate>
    <dc:creator>abo</dc:creator>
    <dc:date>2022-03-15T18:28:44Z</dc:date>
    <item>
      <title>Using REDUCE to Sum a Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536190#M2005810</link>
      <description>&lt;P&gt;How can I convert this to a REDUCE expression ?&lt;/P&gt;
  &lt;P&gt;I can't convert the WHERE to WHILE&lt;/P&gt;
  &lt;P&gt;Thanks&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;DATA header_price TYPE bapicond-cond_value.
LOOP AT order_conditions_in ASSIGNING FIELD-SYMBOL(&amp;lt;cond&amp;gt;) WHERE cond_type = 'PR00'.
  header_price = header_price + &amp;lt;cond&amp;gt;-cond_type.
ENDLOOP.

"Unsuccessful attempt
"Message - The statement before "WHILE ..." was not closed (period missing).
DATA(header_price2) = REDUCE bapicond-cond_value( INIT p = 0 
                                                  FOR prices IN order_conditions_in 
                                                  while prices=&amp;gt;cond_type = 'PR00' 
                                                  NEXT p = p + prices-cond_value ).
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Mar 2022 16:51:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536190#M2005810</guid>
      <dc:creator>ron_mitton</dc:creator>
      <dc:date>2022-03-15T16:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using REDUCE to Sum a Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536191#M2005811</link>
      <description>&lt;P&gt;You have to use WHERE, not WHILE. Why do you want to use WHILE?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 17:28:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536191#M2005811</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-03-15T17:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using REDUCE to Sum a Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536192#M2005812</link>
      <description>&lt;P&gt;The documentation only mentions UNTIL and WHILE&lt;/P&gt;&lt;P&gt;&lt;A href="https://saphtmlphtmlviewer.sap.com/SAPEVENT:ABENCONSTRUCTOR_EXPRESSION_REDUCE"&gt;REDUCE&lt;/A&gt;&lt;I&gt;|&lt;/I&gt;&lt;A href="https://saphtmlphtmlviewer.sap.com/SAPEVENT:ABENNEW_CONSTRUCTOR_PARAMS_ITAB"&gt;NEW&lt;/A&gt;&lt;I&gt;|&lt;/I&gt;&lt;A href="https://saphtmlphtmlviewer.sap.com/SAPEVENT:ABENVALUE_CONSTRUCTOR_PARAMS_ITAB"&gt;VALUE&lt;/A&gt; type( ... FOR &lt;A href="https://saphtmlphtmlviewer.sap.com/SAPEVENT:ABENFOR_CONDITIONAL"&gt;... UNTIL&lt;I&gt;|&lt;/I&gt;WHILE ...&lt;/A&gt;&lt;I&gt;|&lt;/I&gt;&lt;A href="https://saphtmlphtmlviewer.sap.com/SAPEVENT:ABENFOR_ITAB"&gt;... IN ...&lt;/A&gt; ... ) .&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 18:07:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536192#M2005812</guid>
      <dc:creator>ron_mitton</dc:creator>
      <dc:date>2022-03-15T18:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using REDUCE to Sum a Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536193#M2005813</link>
      <description>&lt;P&gt;Here is a &lt;A href="https://github.com/AndreaBorgia-Abo/ABAP-Examples/blob/main/src/video/zabo_reduce_operator.prog.abap" target="_blank"&gt;complete working example&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 18:28:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536193#M2005813</guid>
      <dc:creator>abo</dc:creator>
      <dc:date>2022-03-15T18:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using REDUCE to Sum a Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536194#M2005814</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;This works:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA(header_price) = REDUCE bapicond-cond_value( INIT p = 0 
                      FOR prices IN order_conditions_in 
                      WHERE ( cond_type = 'PR00' ) 
                      NEXT p = p + prices-cond_value ).&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Mar 2022 18:55:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536194#M2005814</guid>
      <dc:creator>ron_mitton</dc:creator>
      <dc:date>2022-03-15T18:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using REDUCE to Sum a Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536195#M2005815</link>
      <description>&lt;P&gt;Please be aware, that &lt;A href="https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenfor.htm"&gt;FOR&lt;/A&gt; has two variants:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FOR ... UNTIL|WHILE ... 
      | ... IN ... &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;FOR ... UNTIL|WHILE has the semantics of statements DO|WHILE.&lt;/P&gt;&lt;P&gt;FOR ... IN has the semantics of LOOP.&lt;/P&gt;&lt;P&gt;You must not mix up the syntax.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 09:16:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536195#M2005815</guid>
      <dc:creator>retired_member</dc:creator>
      <dc:date>2022-03-16T09:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using REDUCE to Sum a Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536196#M2005816</link>
      <description>&lt;P&gt;Hey everyone,&lt;/P&gt;&lt;P&gt;I wrote a small program which does this aggregation in four ways (loop, reduce with for...in...where, while, reduce with for...while). Which one you like most is up to you, I'd go with option 2. &lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;types:
  begin of s_input,
    cond_type  type string,
    cond_value type i,
  end of s_input,
  t_input type standard table of s_input with empty key.


data(lt_input) = value t_input(
  ( cond_type = 'PR00' cond_value = 10 )
  ( cond_type = 'PR01' cond_value = 10 )
  ( cond_type = 'PR00' cond_value = 10 )
  ( cond_type = 'PR01' cond_value = 10 ) ).


" loop 
data lv_header_price1 type i.
loop at lt_input assigning field-symbol(&amp;lt;cond&amp;gt;)
  where cond_type = 'PR00'.

  lv_header_price1 = lv_header_price1 + &amp;lt;cond&amp;gt;-cond_value.
endloop.
write: / lv_header_price1.

" reduce with FOR ... IN ...WHERE
data(lv_header_price2) = reduce i( init p = 0
                                   for prices in lt_input
                                   where ( cond_type = 'PR00' )
                                   next p = p + prices-cond_value ).
write: / lv_header_price2.

" while
data lv_header_price3 type i.
data(lv_index) = 1.
while lv_index &amp;lt; lines( lt_input ) + 1.
  if lt_input[ lv_index ]-cond_type = 'PR00'.
    lv_header_price3 = lv_header_price3 + lt_input[ lv_index ]-cond_value.
  endif.
  lv_index = lv_index + 1.
endwhile.
write: / lv_header_price3.

" reduce with FOR ... WHILE
data(lv_header_price4) = reduce i( init p = 0
                                   for i = 1 while i &amp;lt; lines( lt_input ) + 1
                                   next p = cond #( when lt_input[ i ]-cond_type = 'PR00' then p + lt_input[ i ]-cond_value
                                                    else p ) ).
write: / lv_header_price4.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Mar 2022 14:43:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-reduce-to-sum-a-table/m-p/12536196#M2005816</guid>
      <dc:creator>MichaelSauter</dc:creator>
      <dc:date>2022-03-17T14:43:39Z</dc:date>
    </item>
  </channel>
</rss>

