<?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: ABAP REDUCE with SORT in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413300#M1996602</link>
    <description>&lt;P&gt;Could you show the exact type of I_TAB please?&lt;/P&gt;</description>
    <pubDate>Mon, 26 Apr 2021 12:00:02 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2021-04-26T12:00:02Z</dc:date>
    <item>
      <title>ABAP REDUCE with SORT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413297#M1996599</link>
      <description>&lt;P&gt;Not sure if it's a bug or a feature, but I tried to use REDUCE statement in ABAP with an alphanumeric Internal table. Contents of internal table I_TAB(Inline declaration from SELECT statement) after explicit SORT is as follows:&lt;/P&gt;
  &lt;P&gt;123&lt;/P&gt;
  &lt;P&gt;234&lt;/P&gt;
  &lt;P&gt;345&lt;/P&gt;
  &lt;P&gt;ABC&lt;/P&gt;
  &lt;P&gt;DEF&lt;/P&gt;
  &lt;P&gt;Then I executed the ff REDUCE code:&lt;/P&gt;
  &lt;P&gt;v_string = REDUCE string( INIT text TYPE string sep = '' FOR ls_tab IN i_tab NEXT text = text &amp;amp;&amp;amp; sep &amp;amp;&amp;amp; ls_tab-field1 sep = ',' ).&lt;/P&gt;
  &lt;P&gt;The expected output would have been:&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;"123,234,345,ABC,DEF"&lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;But no, SAP reduced it like this:&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;"ABC,DEF,123,234,345" &lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;Totally ignoring the sort order of the internal table prior to REDUCE. &lt;/P&gt;
  &lt;P&gt;Anyone who has any idea what's going on?&lt;/P&gt;
  &lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 02:50:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413297#M1996599</guid>
      <dc:creator>AdrianDBorja</dc:creator>
      <dc:date>2021-04-26T02:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP REDUCE with SORT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413298#M1996600</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;The &lt;A href="https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenfor_in_itab.htm" target="_blank"&gt;ABAP Documentation for FOR ... IN itab&lt;/A&gt; suggests that:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;As in LOOP, the order of the lines read depends on the table category or a key specified in cond.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;And looking at the &lt;A href="https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaploop_at_itab.htm" target="_blank"&gt;ABAP Documentation for LOOP AT itab, Basic Form&lt;/A&gt;, we see that:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Standard tables and sorted tables&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;The lines are read by ascending line numbers in the primary table index. In each loop pass, the system field sy-tabix contains the line number of the current line in the primary table index.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Hashed tables&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;The lines are processed in the order in which they were inserted into the table, and after a sort using the statement SORT in the sort order. In each loop pass, the system field sy-tabix contains the value 0.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;So I guess it all comes down to the type and declaration of your structure and table, if your result is a bug of a feature... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 04:24:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413298#M1996600</guid>
      <dc:creator>joltdx</dc:creator>
      <dc:date>2021-04-26T04:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP REDUCE with SORT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413299#M1996601</link>
      <description>&lt;P&gt;I would suggest defining the internal table with EMPTY key or using &lt;A href="https://blogs.sap.com/2017/11/30/5-use-cases-of-group-by-for-internal-tables/"&gt;GROUP BY&lt;/A&gt; and with a user-defined ordering&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FOR GROUPS group OF elements IN itab GROUP BY ... ASCENDING&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Apr 2021 07:04:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413299#M1996601</guid>
      <dc:creator>nomssi</dc:creator>
      <dc:date>2021-04-26T07:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP REDUCE with SORT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413300#M1996602</link>
      <description>&lt;P&gt;Could you show the exact type of I_TAB please?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 12:00:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413300#M1996602</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2021-04-26T12:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP REDUCE with SORT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413301#M1996603</link>
      <description>&lt;P&gt;Please check following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES tt_string TYPE STANDARD TABLE OF char100 WITH DEFAULT KEY.
DATA(lt_string) = VALUE tt_string( ( '123' ) ( '234' ) ( '345' ) ( 'ABC' ) ( 'DEF' ) ).
DATA(l_string) = REDUCE string( INIT text TYPE string sep = ''
           FOR ls_tab IN lt_string NEXT text = text &amp;amp;&amp;amp; sep &amp;amp;&amp;amp; ls_tab sep = ',' ).
WRITE l_string.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The output is:&lt;/P&gt;&lt;P&gt;123,234,345,ABC,DEF&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 16:31:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/12413301#M1996603</guid>
      <dc:creator>ThorstenHoefer</dc:creator>
      <dc:date>2021-04-26T16:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP REDUCE with SORT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/14027994#M2038629</link>
      <description>&lt;P&gt;it's inline declaration, as in SELECT * FROM TAB INTO TABLE DATA I_TAB&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 10:05:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/14027994#M2038629</guid>
      <dc:creator>AdrianDBorja</dc:creator>
      <dc:date>2025-02-26T10:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP REDUCE with SORT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/14027997#M2038630</link>
      <description>&lt;P&gt;thanks. then I guess, better explicitly declared internal table rather than inline to not have unexpected behavior&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 10:06:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-reduce-with-sort/m-p/14027997#M2038630</guid>
      <dc:creator>AdrianDBorja</dc:creator>
      <dc:date>2025-02-26T10:06:29Z</dc:date>
    </item>
  </channel>
</rss>

