<?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: How to Sort and Select Maximum in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249960#M1014414</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Sort itab by LIC_ID ROW_ID&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  at end of LIC_ID.&lt;/P&gt;&lt;P&gt;     ....here you will get the maximum of ROW_ID...&lt;/P&gt;&lt;P&gt;  endat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&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;Subramanian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Aug 2008 14:36:46 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-08-08T14:36:46Z</dc:date>
    <item>
      <title>How to Sort and Select Maximum</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249957#M1014411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a list of data which shows the 'workflow' for Licenses (LIC_ID).  Every time a License goes through another stage of the workflow action (AC_ID), another row is added to the table under a new unique identifier (ROW_ID).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I need to do is find the last workflow action which happened to each License.  I think this means I have to sort the table by LIC_ID and the ROW_ID, and then once the table is sorted, pick the maximum ROW_ID per LIC_ID (which will give me the last AC_ID).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hence the after sorting the table looks something like &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ROW_ID&lt;/STRONG&gt;           LIC_ID       &lt;EM&gt;AC_ID&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;                      100           &lt;EM&gt;Start&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;18&lt;/STRONG&gt;                    100           &lt;EM&gt;Process&lt;/EM&gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;25&lt;/STRONG&gt;                    100           &lt;EM&gt;End&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;                      200           &lt;EM&gt;Start&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;9&lt;/STRONG&gt;                      200           &lt;EM&gt;Hold&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;30&lt;/STRONG&gt;                    200           &lt;EM&gt;Cancel&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However I have no idea what the syntax would be to take the highest ROW_ID per LIC_ID. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone help?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know if this does not make sense!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Mischa&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Mischa Gulseven on Aug 8, 2008 4:19 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2008 14:19:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249957#M1014411</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-08T14:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sort and Select Maximum</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249958#M1014412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For example your sorted internal table ITAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
sort itab by row_id descending lic_id descending.

loop at itab.
  at new of lic_id.
    move 'Y' to v_flag.
  endat.
  if v_flag eq 'Y'.
    move-corresponding itab to itab1.
    append itab1.
    clear v_flag.
  endif.
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here ITAB1 contains the maximum ROW_ID per LIC_ID.&lt;/P&gt;&lt;P&gt;a®&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2008 14:35:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249958#M1014412</guid>
      <dc:creator>former_member194669</dc:creator>
      <dc:date>2008-08-08T14:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sort and Select Maximum</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249959#M1014413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If this is in an internal table, you can try something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT tableid.&lt;/P&gt;&lt;P&gt;    AT END OF LIC_ID.&lt;/P&gt;&lt;P&gt;       WRITE:/ LIC_ID, ROW_ID.&lt;/P&gt;&lt;P&gt;    ENDAT.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2008 14:36:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249959#M1014413</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-08T14:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sort and Select Maximum</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249960#M1014414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Sort itab by LIC_ID ROW_ID&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  at end of LIC_ID.&lt;/P&gt;&lt;P&gt;     ....here you will get the maximum of ROW_ID...&lt;/P&gt;&lt;P&gt;  endat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&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;Subramanian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2008 14:36:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249960#M1014414</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-08T14:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sort and Select Maximum</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249961#M1014415</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I really appreciate your help on this, but for some reason the code which you have all recommended "LOOP AT itab" is not working for me.  &lt;/P&gt;&lt;P&gt;I am getting the error message&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"At "LOOP AT itab" one of the additions "INTO", "ASSIGNING" or "TRANSPORTING NO FIELDS" is required in the 00 context."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone tell me where I'm going wrong?&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;P&gt;Mischa&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Aug 2008 10:50:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249961#M1014415</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-12T10:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sort and Select Maximum</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249962#M1014416</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Declare the internal table without header line and use &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab assigning &amp;lt;fs_itab&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab into wa_itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: shakeela Shibu on Aug 12, 2008 1:08 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Aug 2008 11:07:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249962#M1014416</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-12T11:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sort and Select Maximum</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249963#M1014417</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;Try out like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: define var1 and var2 of type lic_id and row_id.&lt;/P&gt;&lt;P&gt;Loop at itab.&lt;/P&gt;&lt;P&gt;at new lic_id.&lt;/P&gt;&lt;P&gt;clear var1.&lt;/P&gt;&lt;P&gt;var1 = itab-lic_id.&lt;/P&gt;&lt;P&gt;endat.&lt;/P&gt;&lt;P&gt;SELECT MAX( row_id )  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INTO (var2 ) from ltab where lic_id = var1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this will help u.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Aug 2008 11:24:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-sort-and-select-maximum/m-p/4249963#M1014417</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-12T11:24:45Z</dc:date>
    </item>
  </channel>
</rss>

