<?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: sorting internal table with variable no of fields in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287983#M498849</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;U can use a number of max fields for sorting:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: FIELD1(30),&lt;/P&gt;&lt;P&gt;          FIELD2(30),&lt;/P&gt;&lt;P&gt;          FIELD3(30).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT ITAB BY (FIELD1) (FIELD2) (FIELD3).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 29 May 2007 12:32:48 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-05-29T12:32:48Z</dc:date>
    <item>
      <title>sorting internal table with variable no of fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287979#M498845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to sort the internal table with variable no of fields . Every time the  report is run the number of fields as well as the sequence by which the table has to be sorted changes . How to do 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;regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 May 2007 12:21:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287979#M498845</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-29T12:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: sorting internal table with variable no of fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287980#M498846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Use the Field Symbols for thisone, pass the value which you want to sort the Internal table, then use this Filed-Symbol to srot the Internal table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt; Sudheer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 May 2007 12:27:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287980#M498846</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-29T12:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: sorting internal table with variable no of fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287981#M498847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please try this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF ITAB OCCURS 0,&lt;/P&gt;&lt;P&gt;        F1(4),&lt;/P&gt;&lt;P&gt;      END OF ITAB.&lt;/P&gt;&lt;P&gt;                                                                        &lt;/P&gt;&lt;P&gt;DATA: BEGIN OF ITAB2 OCCURS 0,&lt;/P&gt;&lt;P&gt;        F1(1),&lt;/P&gt;&lt;P&gt;        F2(1),&lt;/P&gt;&lt;P&gt;        F3(4),&lt;/P&gt;&lt;P&gt;      END OF ITAB2.&lt;/P&gt;&lt;P&gt;                                                                        &lt;/P&gt;&lt;P&gt;ITAB-F1 = '01AC'.&lt;/P&gt;&lt;P&gt;APPEND ITAB.&lt;/P&gt;&lt;P&gt;                                                                        &lt;/P&gt;&lt;P&gt;ITAB-F1 = '02AB'.&lt;/P&gt;&lt;P&gt;APPEND ITAB.&lt;/P&gt;&lt;P&gt;                                                                        &lt;/P&gt;&lt;P&gt;ITAB-F1 = '01CD'.&lt;/P&gt;&lt;P&gt;APPEND ITAB.&lt;/P&gt;&lt;P&gt;                                                                        &lt;/P&gt;&lt;P&gt;ITAB-F1 = '02CA'.&lt;/P&gt;&lt;P&gt;APPEND ITAB.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;LOOP AT ITAB.&lt;/P&gt;&lt;P&gt;  ITAB2-F1 = ITAB-F1+2(1).&lt;/P&gt;&lt;P&gt;  ITAB2-F2 = ITAB-F1+3(1).&lt;/P&gt;&lt;P&gt;  ITAB2-F3 = ITAB-F1.&lt;/P&gt;&lt;P&gt;  APPEND ITAB2.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;                                                                        &lt;/P&gt;&lt;P&gt;SORT ITAB2 BY F1 ASCENDING&lt;/P&gt;&lt;P&gt;              F2 DESCENDING.&lt;/P&gt;&lt;P&gt;                                                                        &lt;/P&gt;&lt;P&gt;LOOP AT ITAB2.&lt;/P&gt;&lt;P&gt;  WRITE: / ITAB2-F3.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REWARD POINTS IF HELPFUL&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 May 2007 12:28:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287981#M498847</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-29T12:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: sorting internal table with variable no of fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287982#M498848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;THEN ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort   the internal table  .....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;example   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort    itab .....   it will sort the  internal table   by   fields  index  like first declared   will sorted first ... then second   ... thrid  ...  n  ...etc..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if  you want to sort any specific  range then  go for   &lt;/P&gt;&lt;P&gt;example &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort  itab  by   first   third  fourth   second  etc ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 May 2007 12:30:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287982#M498848</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-29T12:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: sorting internal table with variable no of fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287983#M498849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;U can use a number of max fields for sorting:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: FIELD1(30),&lt;/P&gt;&lt;P&gt;          FIELD2(30),&lt;/P&gt;&lt;P&gt;          FIELD3(30).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT ITAB BY (FIELD1) (FIELD2) (FIELD3).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 May 2007 12:32:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287983#M498849</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-29T12:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: sorting internal table with variable no of fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287984#M498850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Neelesh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think sorting is not possible by using field symbols, it can be used to modify table contents. This is because field symbol will just point to a line of the table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyways as far as your requirement is concerned if you want your table to be sorted in order of its key fields just use the statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       &amp;lt;b&amp;gt; SORT &amp;lt;itab&amp;gt; [ASCENDING|DESCENDING] &amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variable number of fields will not cause any problem in this. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if you want table to sorted by a different key, you can specify the key in the SORT statement. There you need to know field names (either static or dynamically) . &lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;&lt;/P&gt;&lt;P&gt;SORT &amp;lt;itab&amp;gt; [ASCENDING|DESCENDING] &lt;/P&gt;&lt;P&gt;             BY &amp;lt;f1&amp;gt; [ASCENDING|DESCENDING]&lt;/P&gt;&lt;P&gt;                    ...&lt;/P&gt;&lt;P&gt;                   &amp;lt;fn&amp;gt; [ASCENDING|DESCENDING]&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;f1, f2, ........fn are the fields according to which you want to sort. It can be harcoded or set dynamically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Award points if useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Indrajit.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 May 2007 12:33:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287984#M498850</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-29T12:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: sorting internal table with variable no of fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287985#M498851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;you have to put your fields in an i_tab then use&lt;/P&gt;&lt;P&gt; sort tablename by ( i_tab ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS dbtab TYPE c LENGTH 30.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT-OPTIONS columns FOR dbtab NO INTERVALS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: otab  TYPE abap_sortorder_tab,&lt;/P&gt;&lt;P&gt;      oline TYPE abap_sortorder,&lt;/P&gt;&lt;P&gt;      dref  TYPE REF TO data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS: &amp;lt;column&amp;gt; LIKE LINE OF columns,&lt;/P&gt;&lt;P&gt;               &amp;lt;itab&amp;gt; TYPE STANDARD TABLE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TRY.&lt;/P&gt;&lt;P&gt;    CREATE DATA dref TYPE STANDARD TABLE OF (dbtab).&lt;/P&gt;&lt;P&gt;    ASSIGN dref-&amp;gt;* TO &amp;lt;itab&amp;gt;.&lt;/P&gt;&lt;P&gt;  CATCH cx_sy_create_data_error.&lt;/P&gt;&lt;P&gt;    MESSAGE 'Wrong data type!' TYPE 'I' DISPLAY LIKE 'E'.&lt;/P&gt;&lt;P&gt;    LEAVE PROGRAM.&lt;/P&gt;&lt;P&gt;ENDTRY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TRY.&lt;/P&gt;&lt;P&gt;    SELECT *&lt;/P&gt;&lt;P&gt;           FROM (dbtab)&lt;/P&gt;&lt;P&gt;           INTO TABLE &amp;lt;itab&amp;gt;.&lt;/P&gt;&lt;P&gt;  CATCH cx_sy_dynamic_osql_semantics.&lt;/P&gt;&lt;P&gt;    MESSAGE 'Wrong database table!' TYPE 'I' DISPLAY LIKE 'E'.&lt;/P&gt;&lt;P&gt;    LEAVE PROGRAM.&lt;/P&gt;&lt;P&gt;ENDTRY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT columns ASSIGNING &amp;lt;column&amp;gt;.&lt;/P&gt;&lt;P&gt;  oline-name = &amp;lt;column&amp;gt;-low.&lt;/P&gt;&lt;P&gt;  APPEND oline TO otab.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TRY.&lt;/P&gt;&lt;P&gt;    SORT &amp;lt;itab&amp;gt; BY (otab).&lt;/P&gt;&lt;P&gt;  CATCH cx_sy_dyn_table_ill_comp_val.&lt;/P&gt;&lt;P&gt;    MESSAGE 'Wrong column name!' TYPE 'I' DISPLAY LIKE 'E'.&lt;/P&gt;&lt;P&gt;    LEAVE PROGRAM.&lt;/P&gt;&lt;P&gt;ENDTRY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sooness.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 May 2007 13:05:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorting-internal-table-with-variable-no-of-fields/m-p/2287985#M498851</guid>
      <dc:creator>dev_parbutteea</dc:creator>
      <dc:date>2007-05-29T13:05:30Z</dc:date>
    </item>
  </channel>
</rss>

