<?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: ALV - Sort in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261395#M779245</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ashok , I am giving u a similar sorting problem and solution.pls go through it so that u will get some idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Q: I need to sort the alv after displaying the output.The requirement is the user will select any column in the output and when he presses the sort(Custom Button) Button the entire output has to be displayed in the sort order of that column.Here I am using OOPs Concept.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sol: problem solved using the methods set_sort_criteria and get_selected_columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please find the related code.&lt;/P&gt;&lt;P&gt;any way thank you for all u r replys.&lt;/P&gt;&lt;P&gt;METHOD handle_user_command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;define local data&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:i_col type standard table of LVC_S_COL,&lt;/P&gt;&lt;P&gt;wa_col type LVC_S_COL,&lt;/P&gt;&lt;P&gt;wa_sort TYPE LVC_S_SORT.&lt;/P&gt;&lt;P&gt;CASE e_ucomm.&lt;/P&gt;&lt;P&gt;WHEN 'SORT_COL'.&lt;/P&gt;&lt;P&gt;REFRESH: mt_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL METHOD sender-&amp;gt;get_selected_columns&lt;/P&gt;&lt;P&gt;IMPORTING&lt;/P&gt;&lt;P&gt;ET_INDEX_COLUMNS = i_COL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at i_col into wa_col .&lt;/P&gt;&lt;P&gt;wa_sort-spos = sy-tabix.&lt;/P&gt;&lt;P&gt;wa_sort-fieldname = wa_col-fieldname.&lt;/P&gt;&lt;P&gt;wa_sort-up = 'X'.&lt;/P&gt;&lt;P&gt;append wa_sort to mt_sort.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL METHOD sender-&amp;gt;set_sort_criteria&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;it_sort = mt_sort&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;EXCEPTIONS&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;NO_FIELDCATALOG_AVAILABLE = 1&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;others = 2&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;IF sy-subrc 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL METHOD go_grid-&amp;gt;set_table_for_first_display&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;i_structure_name = 'VBAK'&lt;/P&gt;&lt;P&gt;is_layout = g_layout&lt;/P&gt;&lt;P&gt;CHANGING&lt;/P&gt;&lt;P&gt;it_outtab = g_outtab&lt;/P&gt;&lt;P&gt;it_sort = mt_sort&lt;/P&gt;&lt;P&gt;EXCEPTIONS&lt;/P&gt;&lt;P&gt;OTHERS = 4.&lt;/P&gt;&lt;P&gt;IF sy-subrc 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHEN OTHERS.&lt;/P&gt;&lt;P&gt;ENDCASE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;Hema.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 20 Jan 2008 05:41:10 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-01-20T05:41:10Z</dc:date>
    <item>
      <title>ALV - Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261392#M779242</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; I want to do Total sum and Sub total ZRATE(CURR) with respect to ZCLIENT(Char10).&lt;/P&gt;&lt;P&gt;Can you please what is wrong in my code.&lt;/P&gt;&lt;P&gt;Correct me if i am wrong.&lt;/P&gt;&lt;P&gt;Even DOSUM is also not working....&lt;/P&gt;&lt;P&gt;DEFINE m_fieldcat.&lt;/P&gt;&lt;P&gt;      add 1 to ls_fieldcat-col_pos.&lt;/P&gt;&lt;P&gt;      ls_fieldcat-fieldname   = &amp;amp;1.&lt;/P&gt;&lt;P&gt;      ls_fieldcat-tabname = 'IT_PIPE'.&lt;/P&gt;&lt;P&gt;      ls_fieldcat-seltext_l = &amp;amp;2.&lt;/P&gt;&lt;P&gt;      ls_fieldcat-do_sum = &amp;amp;3.&lt;/P&gt;&lt;P&gt;      append ls_fieldcat to lt_fieldcat.&lt;/P&gt;&lt;P&gt;    END-OF-DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;m_fieldcat 'ZCLIENT' 'Client' ' '.&lt;/P&gt;&lt;P&gt;m_fieldcat 'ZRATE'  'Rate' 'X'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; DEFINE m_sort.&lt;/P&gt;&lt;P&gt;      add 1 to ls_sort-spos.&lt;/P&gt;&lt;P&gt;      ls_sort-fieldname = &amp;amp;1.&lt;/P&gt;&lt;P&gt;      ls_sort-up        = 'X'.&lt;/P&gt;&lt;P&gt;      ls_sort-subtot     = &amp;amp;2.&lt;/P&gt;&lt;P&gt;      append ls_sort to lt_sort.&lt;/P&gt;&lt;P&gt;    END-OF-DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;m_sort 'ZCLIENT ' 'X' .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'&lt;/P&gt;&lt;P&gt;      EXPORTING&lt;/P&gt;&lt;P&gt;        i_callback_program = sy-repid&lt;/P&gt;&lt;P&gt;        it_fieldcat        = lt_fieldcat&lt;/P&gt;&lt;P&gt;        it_sort            = lt_sort&lt;/P&gt;&lt;P&gt;      TABLES&lt;/P&gt;&lt;P&gt;        t_outtab           = it_pipe.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ashok...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Jan 2008 15:09:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261392#M779242</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-19T15:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261393#M779243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;can you try like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DEFINE m_fieldcat.&lt;/P&gt;&lt;P&gt;add 1 to ls_fieldcat-col_pos.&lt;/P&gt;&lt;P&gt;ls_fieldcat-fieldname = &amp;amp;1.&lt;/P&gt;&lt;P&gt;ls_fieldcat-tabname = 'IT_PIPE'.&lt;/P&gt;&lt;P&gt;ls_fieldcat-seltext_l = &amp;amp;2.&lt;/P&gt;&lt;P&gt;ls_fieldcat-do_sum = &amp;amp;3.&lt;/P&gt;&lt;P&gt;append ls_fieldcat to lt_fieldcat.&lt;/P&gt;&lt;P&gt;END-OF-DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;m_fieldcat 'ZCLIENT' 'Client' ' '.&lt;/P&gt;&lt;P&gt;m_fieldcat 'ZRATE' 'Rate' 'X'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DEFINE m_sort.&lt;/P&gt;&lt;P&gt;add 1 to ls_sort-spos.&lt;/P&gt;&lt;P&gt;ls_sort-fieldname = &amp;amp;1.&lt;/P&gt;&lt;P&gt;ls_sort-up = 'X'.&lt;/P&gt;&lt;P&gt;ls_sort-subtot = &amp;amp;2.&lt;/P&gt;&lt;P&gt;append ls_sort to lt_sort.&lt;/P&gt;&lt;P&gt;END-OF-DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;m_sort 'ZCLIENT ' ' ' .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;m_sort 'ZRATE'  'X'.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;i_callback_program = sy-repid&lt;/P&gt;&lt;P&gt;it_fieldcat = lt_fieldcat&lt;/P&gt;&lt;P&gt;it_sort = lt_sort&lt;/P&gt;&lt;P&gt;TABLES&lt;/P&gt;&lt;P&gt;t_outtab = it_pipe.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Jan 2008 16:17:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261393#M779243</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-19T16:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261394#M779244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ashok,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The macro is fine. check the code below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT-SPOS = &amp;amp;1.&lt;/P&gt;&lt;P&gt;SORT-FIELDNAME = &amp;amp;2.&lt;/P&gt;&lt;P&gt;SORT-TABNAME = 'TT_ITAB'.&lt;/P&gt;&lt;P&gt;SORT-UP = 'X'.&lt;/P&gt;&lt;P&gt;APPEND SORT.&lt;/P&gt;&lt;P&gt;CLEAR SORT.&lt;/P&gt;&lt;P&gt;END-OF-DEFINITION.&lt;/P&gt;&lt;P&gt;MACROS1 '1' 'EBELN'.&lt;/P&gt;&lt;P&gt;MACROS1 '2' 'AEDAT'.&lt;/P&gt;&lt;P&gt;MACROS1 '3' 'LIFNR'.&lt;/P&gt;&lt;P&gt;MACROS1 '4' 'EKGRP'. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code is to sort 4 fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;Hema.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Jan 2008 05:33:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261394#M779244</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-20T05:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261395#M779245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ashok , I am giving u a similar sorting problem and solution.pls go through it so that u will get some idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Q: I need to sort the alv after displaying the output.The requirement is the user will select any column in the output and when he presses the sort(Custom Button) Button the entire output has to be displayed in the sort order of that column.Here I am using OOPs Concept.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sol: problem solved using the methods set_sort_criteria and get_selected_columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please find the related code.&lt;/P&gt;&lt;P&gt;any way thank you for all u r replys.&lt;/P&gt;&lt;P&gt;METHOD handle_user_command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;define local data&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:i_col type standard table of LVC_S_COL,&lt;/P&gt;&lt;P&gt;wa_col type LVC_S_COL,&lt;/P&gt;&lt;P&gt;wa_sort TYPE LVC_S_SORT.&lt;/P&gt;&lt;P&gt;CASE e_ucomm.&lt;/P&gt;&lt;P&gt;WHEN 'SORT_COL'.&lt;/P&gt;&lt;P&gt;REFRESH: mt_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL METHOD sender-&amp;gt;get_selected_columns&lt;/P&gt;&lt;P&gt;IMPORTING&lt;/P&gt;&lt;P&gt;ET_INDEX_COLUMNS = i_COL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at i_col into wa_col .&lt;/P&gt;&lt;P&gt;wa_sort-spos = sy-tabix.&lt;/P&gt;&lt;P&gt;wa_sort-fieldname = wa_col-fieldname.&lt;/P&gt;&lt;P&gt;wa_sort-up = 'X'.&lt;/P&gt;&lt;P&gt;append wa_sort to mt_sort.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL METHOD sender-&amp;gt;set_sort_criteria&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;it_sort = mt_sort&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;EXCEPTIONS&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;NO_FIELDCATALOG_AVAILABLE = 1&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;others = 2&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;IF sy-subrc 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL METHOD go_grid-&amp;gt;set_table_for_first_display&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;i_structure_name = 'VBAK'&lt;/P&gt;&lt;P&gt;is_layout = g_layout&lt;/P&gt;&lt;P&gt;CHANGING&lt;/P&gt;&lt;P&gt;it_outtab = g_outtab&lt;/P&gt;&lt;P&gt;it_sort = mt_sort&lt;/P&gt;&lt;P&gt;EXCEPTIONS&lt;/P&gt;&lt;P&gt;OTHERS = 4.&lt;/P&gt;&lt;P&gt;IF sy-subrc 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHEN OTHERS.&lt;/P&gt;&lt;P&gt;ENDCASE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;Hema.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Jan 2008 05:41:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261395#M779245</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-20T05:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261396#M779246</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;In order to display an ALV report with specific columns already sorted by default you will need to build a&lt;/P&gt;&lt;P&gt;sort catalogue. This is fairly straight forward and is done in the following way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step 1. Add data declaration for sort catalogue&lt;/P&gt;&lt;P&gt;Step 2. Add code to build sort catalogue table&lt;/P&gt;&lt;P&gt;Step 3. Update 'REUSE_ALV_GRID_DISPLAY' FM call to include parameter 'it_sort'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ALV data declarations &lt;/P&gt;&lt;P&gt;data: it_sortcat type slis_sortinfo_alv occurs 1,&lt;/P&gt;&lt;P&gt;wa_sort like line of it_sortcat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;perform build_sortcat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;----&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------" /&gt;&lt;P&gt;*&amp;amp; Form build_sortcat&lt;/P&gt;&lt;P&gt;&amp;amp;----&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Build Sort catalog &lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="------------------------------------------------------------------" /&gt;&lt;P&gt;FORM build_sortcat .&lt;/P&gt;&lt;P&gt;wa_sort-spos = 1.&lt;/P&gt;&lt;P&gt;wa_sort-fieldname = 'EBELN'.&lt;/P&gt;&lt;P&gt;wa_sort-SUBTOT = 'X'. "subtotals any totals column by this field&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gd_sortcat-tabname &lt;/P&gt;&lt;P&gt;APPEND wa_sort TO it_sortcat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa_sort-spos = 2.&lt;/P&gt;&lt;P&gt;wa_sort-fieldname = 'EBELP'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gd_sortcat-tabname &lt;/P&gt;&lt;P&gt;APPEND wa_sort TO it_sortcat.&lt;/P&gt;&lt;P&gt;ENDFORM. " build_sortcat&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;call function 'REUSE_ALV_GRID_DISPLAY'&lt;/P&gt;&lt;P&gt;exporting&lt;/P&gt;&lt;P&gt;i_callback_program = gd_repid&lt;/P&gt;&lt;P&gt;i_callback_top_of_page = 'TOP-OF-PAGE'&lt;/P&gt;&lt;P&gt;is_layout = gd_layout&lt;/P&gt;&lt;P&gt;it_fieldcat = fieldcatalog[]&lt;/P&gt;&lt;P&gt;it_sort = it_sortcat&lt;/P&gt;&lt;P&gt;i_save = 'X'&lt;/P&gt;&lt;P&gt;tables&lt;/P&gt;&lt;P&gt;t_outtab = it_ekko&lt;/P&gt;&lt;P&gt;exceptions&lt;/P&gt;&lt;P&gt;program_error = 1&lt;/P&gt;&lt;P&gt;others = 2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Jan 2008 06:38:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261396#M779246</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-20T06:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: ALV - Sort</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261397#M779247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have to use ls_fieldcat-do_sum statement in your coding &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this sample coding&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;code&amp;amp;----&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;*&amp;amp; Report ZALVTOTAL *&lt;/P&gt;&lt;P&gt;*&amp;amp; *&lt;/P&gt;&lt;P&gt;&amp;amp;----&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;*&amp;amp; *&lt;/P&gt;&lt;P&gt;*&amp;amp; *&lt;/P&gt;&lt;P&gt;&amp;amp;----&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT ZALVTOTAL .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES :&lt;/P&gt;&lt;P&gt;BEGIN OF ty_vbak,&lt;/P&gt;&lt;P&gt;vkorg TYPE vbak-vkorg, " Sales organization&lt;/P&gt;&lt;P&gt;kunnr TYPE vbak-kunnr, " Sold-to party&lt;/P&gt;&lt;P&gt;vbeln TYPE vbak-vbeln, " Sales document&lt;/P&gt;&lt;P&gt;netwr TYPE vbak-netwr, " Net Value of the Sales Order&lt;/P&gt;&lt;P&gt;waerk TYPE vbak-waerk, " Document currency&lt;/P&gt;&lt;P&gt;END OF ty_vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;vbak TYPE vbak,&lt;/P&gt;&lt;P&gt;gt_vbak TYPE TABLE OF ty_vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT-OPTIONS :&lt;/P&gt;&lt;P&gt;s_vkorg FOR vbak-vkorg, " Sales organization&lt;/P&gt;&lt;P&gt;s_kunnr FOR vbak-kunnr, " Sold-to party&lt;/P&gt;&lt;P&gt;s_vbeln FOR vbak-vbeln. " Sales document&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECTION-SCREEN :&lt;/P&gt;&lt;P&gt;SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.&lt;/P&gt;&lt;P&gt;PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.&lt;/P&gt;&lt;P&gt;SELECTION-SCREEN END OF LINE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt;INITIALIZATION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;v_1 = 'Maximum of records to read'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PERFORM f_read_data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PERFORM f_display_data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Form f_read_data&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt;FORM f_read_data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT vkorg kunnr vbeln netwr waerk&lt;/P&gt;&lt;P&gt;UP TO p_max ROWS&lt;/P&gt;&lt;P&gt;INTO TABLE gt_vbak&lt;/P&gt;&lt;P&gt;FROM vbak&lt;/P&gt;&lt;P&gt;WHERE kunnr IN s_kunnr&lt;/P&gt;&lt;P&gt;AND vbeln IN s_vbeln&lt;/P&gt;&lt;P&gt;AND vkorg IN s_vkorg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM. " F_READ_DATA&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Form f_display_data&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt; FORM f_display_data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPE-POOLS: slis. " ALV Global types&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DEFINE m_fieldcat.&lt;/P&gt;&lt;P&gt;add 1 to ls_fieldcat-col_pos.&lt;/P&gt;&lt;P&gt;ls_fieldcat-fieldname = &amp;amp;1.&lt;/P&gt;&lt;P&gt;ls_fieldcat-ref_tabname = 'VBAK'.&lt;/P&gt;&lt;P&gt;ls_fieldcat-do_sum = &amp;amp;2.&lt;/P&gt;&lt;P&gt;ls_fieldcat-cfieldname = &amp;amp;3.&lt;/P&gt;&lt;P&gt;append ls_fieldcat to lt_fieldcat.&lt;/P&gt;&lt;P&gt;END-OF-DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DEFINE m_sort.&lt;/P&gt;&lt;P&gt;add 1 to ls_sort-spos.&lt;/P&gt;&lt;P&gt;ls_sort-fieldname = &amp;amp;1.&lt;/P&gt;&lt;P&gt;ls_sort-up = 'X'.&lt;/P&gt;&lt;P&gt;ls_sort-subtot = &amp;amp;2.&lt;/P&gt;&lt;P&gt;append ls_sort to lt_sort.&lt;/P&gt;&lt;P&gt;END-OF-DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;ls_fieldcat TYPE slis_fieldcat_alv,&lt;/P&gt;&lt;P&gt;lt_fieldcat TYPE slis_t_fieldcat_alv,&lt;/P&gt;&lt;P&gt;lt_sort TYPE slis_t_sortinfo_alv,&lt;/P&gt;&lt;P&gt;ls_sort TYPE slis_sortinfo_alv,&lt;/P&gt;&lt;P&gt;ls_layout TYPE slis_layout_alv.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;m_fieldcat 'VKORG' '' ''.&lt;/P&gt;&lt;P&gt;m_fieldcat 'KUNNR' '' ''.&lt;/P&gt;&lt;P&gt;m_fieldcat 'VBELN' '' ''.&lt;/P&gt;&lt;P&gt;m_fieldcat 'NETWR' 'X' 'WAERK'.&lt;/P&gt;&lt;P&gt;m_fieldcat 'WAERK' '' ''.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;m_sort 'VKORG' 'X'. " Sort by vkorg and subtotal&lt;/P&gt;&lt;P&gt;m_sort 'KUNNR' 'X'. " Sort by kunnr and subtotal&lt;/P&gt;&lt;P&gt;m_sort 'VBELN' ''. " Sort by vbeln&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ls_layout-cell_merge = 'X'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;is_layout = ls_layout&lt;/P&gt;&lt;P&gt;it_fieldcat = lt_fieldcat&lt;/P&gt;&lt;P&gt;it_sort = lt_sort&lt;/P&gt;&lt;P&gt;TABLES&lt;/P&gt;&lt;P&gt;t_outtab = gt_vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM. " F_DISPLAY_DATA[/code]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Jan 2008 06:38:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-sort/m-p/3261397#M779247</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-20T06:38:58Z</dc:date>
    </item>
  </channel>
</rss>

