<?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 USING `FUNCTION MODULE in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621797#M872560</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi saritha,&lt;/P&gt;&lt;P&gt;The functional module for gand total can be obtained like this,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the totals of each currencies, I just inserted the following code in my form 'fill_fieldcat':&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa_fieldcat-fieldname = 'DMBTR'.&lt;/P&gt;&lt;P&gt;wa_fieldcat-ref_fieldname = 'DMBTR'.&lt;/P&gt;&lt;P&gt;wa_fieldcat-ref_tabname = 'BSEG'.&lt;/P&gt;&lt;P&gt;wa_fieldcat-cfieldname = 'WAERS'&lt;/P&gt;&lt;P&gt;APPEND wa_fieldcat TO it_fieldcat.&lt;/P&gt;&lt;P&gt;CLEAR wa_fieldcat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And of course, there must be a currency field that will serve as the reference for the calculation of totals for the different currencies&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also refer this code&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 sub_field_cat&lt;/P&gt;&lt;P&gt;&amp;amp;----&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;text&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 sub_field_cat .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'PERNR'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-003.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 0.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 8.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'WORKDATE'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-012.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 1.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 8.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'WEKLY'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-015.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 2.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 7.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'LGART'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-013.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 3.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 4.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'STDAZ'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-014.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 4.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 7.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'RAUFNR'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-016.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 5.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 12.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM. " sub_field_cat&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 sub_display_data&lt;/P&gt;&lt;P&gt;&amp;amp;----&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;text&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;FORM sub_display_data .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--To sort the output through material number&lt;/P&gt;&lt;P&gt;DATA : lwa_sort TYPE slis_sortinfo_alv.&lt;/P&gt;&lt;P&gt;DATA : lit_sort TYPE slis_t_sortinfo_alv.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Pass the values to the table&lt;/P&gt;&lt;P&gt;lwa_sort-fieldname = 'PERNR'. "Field name in o/p inttable&lt;/P&gt;&lt;P&gt;lwa_sort-tabname = 'it_final2'. "Output Internal table&lt;/P&gt;&lt;P&gt;lwa_sort-spos = '1'. "Sort sequence&lt;/P&gt;&lt;P&gt;lwa_sort-up = 'X'. "Sort in ascending order&lt;/P&gt;&lt;P&gt;lwa_sort-down = ' '. "Sort in descending order&lt;/P&gt;&lt;P&gt;lwa_sort-subtot = 'X'. "Subtotal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND lwa_sort TO lit_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Pass the values to the table&lt;/P&gt;&lt;P&gt;lwa_sort-fieldname = 'WORKDATE'. "Field name in o/p inttable&lt;/P&gt;&lt;P&gt;lwa_sort-tabname = 'it_final2'. "Output Internal table&lt;/P&gt;&lt;P&gt;lwa_sort-spos = '2'. "Sort sequence&lt;/P&gt;&lt;P&gt;lwa_sort-up = 'X'. "Sort in ascending order&lt;/P&gt;&lt;P&gt;lwa_sort-down = ' '. "Sort in descending order&lt;/P&gt;&lt;P&gt;lwa_sort-subtot = ' '. "Subtotal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND lwa_sort TO lit_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Pass the values to the table&lt;/P&gt;&lt;P&gt;lwa_sort-fieldname = 'WEKLY'. "Field name in o/p inttable&lt;/P&gt;&lt;P&gt;lwa_sort-tabname = 'it_final2'. "Output Internal table&lt;/P&gt;&lt;P&gt;lwa_sort-spos = '3'. "Sort sequence&lt;/P&gt;&lt;P&gt;lwa_sort-up = 'X'. "Sort in ascending order&lt;/P&gt;&lt;P&gt;lwa_sort-down = ' '. "Sort in descending order&lt;/P&gt;&lt;P&gt;lwa_sort-subtot = ' '. "Subtotal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND lwa_sort TO lit_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa_layout-colwidth_optimize = 'X'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF NOT it_final2[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Call the function module to display the ALV report&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 = wa_layout&lt;/P&gt;&lt;P&gt;i_callback_program = v_repid&lt;/P&gt;&lt;P&gt;it_fieldcat = it_fieldcat1[]&lt;/P&gt;&lt;P&gt;i_default = c_chk&lt;/P&gt;&lt;P&gt;i_save = c_save&lt;/P&gt;&lt;P&gt;it_sort = lit_sort&lt;/P&gt;&lt;P&gt;TABLES&lt;/P&gt;&lt;P&gt;t_outtab = it_final2&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;P&gt;IF sy-subrc 0.&lt;/P&gt;&lt;P&gt;MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno&lt;/P&gt;&lt;P&gt;WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ELSE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Message No data found&lt;/P&gt;&lt;P&gt;MESSAGE i888 WITH text-017.&lt;/P&gt;&lt;P&gt;LEAVE LIST-PROCESSING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM. " sub_display_data&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And for regarding the sorting please read the below documentation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When ever we select data from data base table to internal table it may/maynot come in sorted order by primary keys of the table. Same SELECT Query may return different order of records for different executions.To ensure that our records in internal table are in proper order before using them we will use the statement SORT. Also if u want to arrange the records of the internal table based on non primary keys or combination of primary and nonprimary keys then we will use sort statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from the above documentation  i think it is clear that we have to perform sort for the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if usefull,&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; regards,&lt;/P&gt;&lt;P&gt;Kalyan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 Apr 2008 18:11:13 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-04-02T18:11:13Z</dc:date>
    <item>
      <title>ALV USING `FUNCTION MODULE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621794#M872557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1.WHAT IS THE PROCEDURE TO &lt;STRONG&gt;GRAND TOTAL CURRENCY FIELDS&lt;/STRONG&gt; BY USING ALV WITH FM?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. WHAT IS THE &lt;STRONG&gt;PURPOSE OF IT_SORT&lt;/STRONG&gt; IN ALV_GRID_DISPLAY?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3. WHILE DOING SUBTOTAL &amp;amp; GRANDTOTAL TO THE FIELDS , IS IT COMPULSORY TO DO SORTING, IF SO PLZ EXPLAIN?&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;KINDLY HELP ME.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Apr 2008 15:49:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621794#M872557</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-02T15:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: ALV USING `FUNCTION MODULE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621795#M872558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Not quite sure about requirement.&lt;/P&gt;&lt;P&gt;2. You can do a sorting before displaying data.&lt;/P&gt;&lt;P&gt;3. No need to do that at all, but would be better for subtotals for example.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Apr 2008 15:52:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621795#M872558</guid>
      <dc:creator>Sm1tje</dc:creator>
      <dc:date>2008-04-02T15:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: ALV USING `FUNCTION MODULE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621796#M872559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check this program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BCALV_TEST_FULLSCREEN&lt;/P&gt;&lt;P&gt;You have to build sort for the totals and subtotals.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;Vamshi.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Apr 2008 16:04:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621796#M872559</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-02T16:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: ALV USING `FUNCTION MODULE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621797#M872560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi saritha,&lt;/P&gt;&lt;P&gt;The functional module for gand total can be obtained like this,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the totals of each currencies, I just inserted the following code in my form 'fill_fieldcat':&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa_fieldcat-fieldname = 'DMBTR'.&lt;/P&gt;&lt;P&gt;wa_fieldcat-ref_fieldname = 'DMBTR'.&lt;/P&gt;&lt;P&gt;wa_fieldcat-ref_tabname = 'BSEG'.&lt;/P&gt;&lt;P&gt;wa_fieldcat-cfieldname = 'WAERS'&lt;/P&gt;&lt;P&gt;APPEND wa_fieldcat TO it_fieldcat.&lt;/P&gt;&lt;P&gt;CLEAR wa_fieldcat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And of course, there must be a currency field that will serve as the reference for the calculation of totals for the different currencies&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also refer this code&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 sub_field_cat&lt;/P&gt;&lt;P&gt;&amp;amp;----&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;text&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 sub_field_cat .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'PERNR'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-003.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 0.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 8.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'WORKDATE'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-012.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 1.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 8.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'WEKLY'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-015.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 2.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 7.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'LGART'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-013.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 3.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 4.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'STDAZ'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-014.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 4.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 7.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_fieldcat1-fieldname = 'RAUFNR'.&lt;/P&gt;&lt;P&gt;it_fieldcat1-seltext_m = text-016.&lt;/P&gt;&lt;P&gt;it_fieldcat1-col_pos = 5.&lt;/P&gt;&lt;P&gt;it_fieldcat1-outputlen = 12.&lt;/P&gt;&lt;P&gt;APPEND it_fieldcat1 TO it_fieldcat1.&lt;/P&gt;&lt;P&gt;CLEAR it_fieldcat1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM. " sub_field_cat&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 sub_display_data&lt;/P&gt;&lt;P&gt;&amp;amp;----&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;text&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;FORM sub_display_data .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--To sort the output through material number&lt;/P&gt;&lt;P&gt;DATA : lwa_sort TYPE slis_sortinfo_alv.&lt;/P&gt;&lt;P&gt;DATA : lit_sort TYPE slis_t_sortinfo_alv.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Pass the values to the table&lt;/P&gt;&lt;P&gt;lwa_sort-fieldname = 'PERNR'. "Field name in o/p inttable&lt;/P&gt;&lt;P&gt;lwa_sort-tabname = 'it_final2'. "Output Internal table&lt;/P&gt;&lt;P&gt;lwa_sort-spos = '1'. "Sort sequence&lt;/P&gt;&lt;P&gt;lwa_sort-up = 'X'. "Sort in ascending order&lt;/P&gt;&lt;P&gt;lwa_sort-down = ' '. "Sort in descending order&lt;/P&gt;&lt;P&gt;lwa_sort-subtot = 'X'. "Subtotal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND lwa_sort TO lit_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Pass the values to the table&lt;/P&gt;&lt;P&gt;lwa_sort-fieldname = 'WORKDATE'. "Field name in o/p inttable&lt;/P&gt;&lt;P&gt;lwa_sort-tabname = 'it_final2'. "Output Internal table&lt;/P&gt;&lt;P&gt;lwa_sort-spos = '2'. "Sort sequence&lt;/P&gt;&lt;P&gt;lwa_sort-up = 'X'. "Sort in ascending order&lt;/P&gt;&lt;P&gt;lwa_sort-down = ' '. "Sort in descending order&lt;/P&gt;&lt;P&gt;lwa_sort-subtot = ' '. "Subtotal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND lwa_sort TO lit_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Pass the values to the table&lt;/P&gt;&lt;P&gt;lwa_sort-fieldname = 'WEKLY'. "Field name in o/p inttable&lt;/P&gt;&lt;P&gt;lwa_sort-tabname = 'it_final2'. "Output Internal table&lt;/P&gt;&lt;P&gt;lwa_sort-spos = '3'. "Sort sequence&lt;/P&gt;&lt;P&gt;lwa_sort-up = 'X'. "Sort in ascending order&lt;/P&gt;&lt;P&gt;lwa_sort-down = ' '. "Sort in descending order&lt;/P&gt;&lt;P&gt;lwa_sort-subtot = ' '. "Subtotal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND lwa_sort TO lit_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa_layout-colwidth_optimize = 'X'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF NOT it_final2[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Call the function module to display the ALV report&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 = wa_layout&lt;/P&gt;&lt;P&gt;i_callback_program = v_repid&lt;/P&gt;&lt;P&gt;it_fieldcat = it_fieldcat1[]&lt;/P&gt;&lt;P&gt;i_default = c_chk&lt;/P&gt;&lt;P&gt;i_save = c_save&lt;/P&gt;&lt;P&gt;it_sort = lit_sort&lt;/P&gt;&lt;P&gt;TABLES&lt;/P&gt;&lt;P&gt;t_outtab = it_final2&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;P&gt;IF sy-subrc 0.&lt;/P&gt;&lt;P&gt;MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno&lt;/P&gt;&lt;P&gt;WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ELSE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Message No data found&lt;/P&gt;&lt;P&gt;MESSAGE i888 WITH text-017.&lt;/P&gt;&lt;P&gt;LEAVE LIST-PROCESSING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM. " sub_display_data&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And for regarding the sorting please read the below documentation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When ever we select data from data base table to internal table it may/maynot come in sorted order by primary keys of the table. Same SELECT Query may return different order of records for different executions.To ensure that our records in internal table are in proper order before using them we will use the statement SORT. Also if u want to arrange the records of the internal table based on non primary keys or combination of primary and nonprimary keys then we will use sort statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from the above documentation  i think it is clear that we have to perform sort for the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if usefull,&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; regards,&lt;/P&gt;&lt;P&gt;Kalyan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Apr 2008 18:11:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621797#M872560</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-02T18:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: ALV USING `FUNCTION MODULE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621798#M872561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Saritha,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       1.  To do grand totals , in the Field catalog for that  currency fields&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;                   wa_fieldcat-datatype = 'CURR'.&lt;/P&gt;&lt;P&gt;                   wa_fieldcat-DOSUM = 'SUM'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          2 . IT_SORT  is used to  do subtotals in ALV&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;         3 .  No it is not compulsort to SORT itab but it is better to do sorting&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Apr 2008 18:22:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-using-function-module/m-p/3621798#M872561</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-02T18:22:50Z</dc:date>
    </item>
  </channel>
</rss>

