<?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 Subtotal based on specific fields in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998543#M1606459</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandeep,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob is correct: The best way is to set the sorts and subtotal flag on the grid and save it as a default layout.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to do it programmatically, you will probably use the only officially released objects, the SALV classes. Then the subtotal coding will look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;...
  DATA:
    lo_sort                  TYPE REF TO cl_salv_sort,
    lo_sorts                 TYPE REF TO cl_salv_sorts,
...
lo_sorts = mo_salv-&amp;gt;get_sorts( ).
...
* subtotal compressed
                TRY.
                    lo_sort = lo_sorts-&amp;gt;add_sort( &amp;lt;column_ref&amp;gt;-columnname ).
                    lo_sort-&amp;gt;set_sequence( )." IF_SALV_C_SORT=&amp;gt;SORT_UP
                    lo_sort-&amp;gt;set_subtotal( )." IF_SALV_C_BOOL_SAP=&amp;gt;TRUE
                    lo_sorts-&amp;gt;set_compressed_subtotal( &amp;lt;column_ref&amp;gt;-columnname ).
                  CATCH cx_root INTO mo_exception.
                ENDTRY.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For more advice on SALV you may search the SCN blogs and wikis and the forum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Jun 2011 14:59:02 GMT</pubDate>
    <dc:creator>Clemenss</dc:creator>
    <dc:date>2011-06-13T14:59:02Z</dc:date>
    <item>
      <title>ALV Subtotal based on specific fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998539#M1606455</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 have a requirement as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In ALV Grid:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have to display subtotal for a field(Currency) , based on two fields (document and material). When the user executes, he should be able to see the subtotals based on these two fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I have to diaply grand total, based on document number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you please help me out for the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sandeep&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2011 13:58:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998539#M1606455</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-06-13T13:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: ALV Subtotal based on specific fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998540#M1606456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Create a default display variant for the report.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2011 14:05:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998540#M1606456</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-06-13T14:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: ALV Subtotal based on specific fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998541#M1606457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you please help me, how can I do that..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My display should be like below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Document       Material               Amount&lt;/P&gt;&lt;P&gt;1                       A                        10&lt;/P&gt;&lt;P&gt;1                       A                         10&lt;/P&gt;&lt;P&gt;1                       A                         10&lt;/P&gt;&lt;P&gt;Toatl Amount                            -&lt;/P&gt;&lt;HR originaltext="-------------" /&gt;&lt;P&gt;                                                    30&lt;/P&gt;&lt;P&gt;                                                -&lt;/P&gt;&lt;HR originaltext="----------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1                    B                           10&lt;/P&gt;&lt;P&gt;1                    B                            10&lt;/P&gt;&lt;P&gt;1                    B                            10&lt;/P&gt;&lt;P&gt;Subto total                                   30&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Total                                             60&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;like that to all....other documents....&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;Sandeep&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2011 14:45:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998541#M1606457</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-06-13T14:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: ALV Subtotal based on specific fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998542#M1606458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandeep;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have 2 way for this question.&lt;/P&gt;&lt;P&gt;First way as Rob say. But this way has one problem. if somebody has authority for change alv layout, He/She can change your layout.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Second way  You can change/write your code. If This case is better for you. Please apply below code. &lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
FORM ALV_FCAT .
"write DO_SUM property
endform.
FORM ALV_SORT.
  CLEAR : SSORT, TSORT.
  REFRESH : TSORT.
  SSORT-SPOS = '1' .
  SSORT-FIELDNAME = 'xxx' .
  SSORT-UP = 'X' . "A to Z
  APPEND SSORT TO TSORT .
  SSORT-SPOS = '2' .
  SSORT-FIELDNAME = 'yyy' .
  SSORT-UP = 'X' . "A to Z
  SSORT-SUBTOT = 'X'.
  APPEND SSORT TO TSORT .
ENDFORM.    

FORM DISPLAY_ALV .
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' " REUSE_ALV_GRID_DISPLAY
  Exporting
     ...
     IT_FIELDCAT              = TFCAT[]
     IT_SORT                  = TSORT[]
     ...

endform.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2011 14:50:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998542#M1606458</guid>
      <dc:creator>former_member212713</dc:creator>
      <dc:date>2011-06-13T14:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: ALV Subtotal based on specific fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998543#M1606459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandeep,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob is correct: The best way is to set the sorts and subtotal flag on the grid and save it as a default layout.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to do it programmatically, you will probably use the only officially released objects, the SALV classes. Then the subtotal coding will look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;...
  DATA:
    lo_sort                  TYPE REF TO cl_salv_sort,
    lo_sorts                 TYPE REF TO cl_salv_sorts,
...
lo_sorts = mo_salv-&amp;gt;get_sorts( ).
...
* subtotal compressed
                TRY.
                    lo_sort = lo_sorts-&amp;gt;add_sort( &amp;lt;column_ref&amp;gt;-columnname ).
                    lo_sort-&amp;gt;set_sequence( )." IF_SALV_C_SORT=&amp;gt;SORT_UP
                    lo_sort-&amp;gt;set_subtotal( )." IF_SALV_C_BOOL_SAP=&amp;gt;TRUE
                    lo_sorts-&amp;gt;set_compressed_subtotal( &amp;lt;column_ref&amp;gt;-columnname ).
                  CATCH cx_root INTO mo_exception.
                ENDTRY.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For more advice on SALV you may search the SCN blogs and wikis and the forum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2011 14:59:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-subtotal-based-on-specific-fields/m-p/7998543#M1606459</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2011-06-13T14:59:02Z</dc:date>
    </item>
  </channel>
</rss>

