<?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: SALV - sorting and aggregation in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401999#M1995736</link>
    <description>&lt;P&gt;Thank you &lt;SPAN class="mention-scrubbed"&gt;touzik_itc&lt;/SPAN&gt;, will try it&lt;/P&gt;</description>
    <pubDate>Fri, 09 Apr 2021 08:03:42 GMT</pubDate>
    <dc:creator>Flavio</dc:creator>
    <dc:date>2021-04-09T08:03:42Z</dc:date>
    <item>
      <title>SALV - sorting and aggregation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401994#M1995731</link>
      <description>&lt;P&gt;Dear all, &lt;/P&gt;
  &lt;P&gt;I've the following question concerning the Salv model with sorting and aggregation: assuming to have the sorting, as follows:&lt;/P&gt;
  &lt;P&gt;1. 'Type of report' (i.e. Production / Shipment)&lt;BR /&gt;2. 'Plant'&lt;BR /&gt;3. 'Family of product' (i.e. Raw material / SemiFinished / Finished / etc)&lt;/P&gt;
  &lt;P&gt;and doing aggregation (sum) on these, I'm wondering if it's possible to add an extra level for again the 'Family of product', just before the 'Type of report'; &lt;/P&gt;
  &lt;P&gt;that is to say, before having the grand total about, for instance, 'Production', I would like to have the total for all Plants concerning the 'Families';&lt;/P&gt;
  &lt;P&gt;I hope I've been clear enough...&lt;/P&gt;
  &lt;P&gt;Any help is highly appreciated!&lt;/P&gt;
  &lt;P&gt;Thanks and best regards,&lt;/P&gt;
  &lt;P&gt;Flavio&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 12:47:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401994#M1995731</guid>
      <dc:creator>Flavio</dc:creator>
      <dc:date>2021-04-06T12:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: SALV - sorting and aggregation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401995#M1995732</link>
      <description>&lt;P&gt;An intermediate summation level? Not sure it can be done but I'm following the question out of curiosity &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 12:55:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401995#M1995732</guid>
      <dc:creator>abo</dc:creator>
      <dc:date>2021-04-06T12:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: SALV - sorting and aggregation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401996#M1995733</link>
      <description>&lt;P&gt;Could you tell us again what result you expect? Below is standard output:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;      Type   Plant  Family  Number1
      Prod   PL1    FAM1    10
      Prod   PL1    FAM1    15
Total Prod   PL1    FAM1    25
      Prod   PL1    FAM2     7
Total Prod   PL1    FAM2     7
Total Prod   PL1            32
      Prod   PL2    FAM1     1
Total Prod   PL2    FAM1     1
Total Prod   PL2             1
Total Prod                  33
Total                       33&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Apr 2021 15:25:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401996#M1995733</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2021-04-06T15:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: SALV - sorting and aggregation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401997#M1995734</link>
      <description>&lt;P&gt;thank you for the interest, &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;here the expected result, if possible (added FAM1 &amp;amp; FAM2 subtotals, before 'Total Prod'):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;      Type   Plant  Family  Number1
      Prod   PL1    FAM1    10
      Prod   PL1    FAM1    15
Total Prod   PL1    FAM1    25
      Prod   PL1    FAM2     7
Total Prod   PL1    FAM2     7
Total Prod   PL1            32
      Prod   PL2    FAM1     1
Total Prod   PL2    FAM1     1
Total Prod   PL2             1
Total Prod          FAM1    26
Total Prod          FAM2     7
Total Prod                  33
Total                       33&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Apr 2021 15:37:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401997#M1995734</guid>
      <dc:creator>Flavio</dc:creator>
      <dc:date>2021-04-06T15:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: SALV - sorting and aggregation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401998#M1995735</link>
      <description>&lt;P&gt;One option is to calculate subtotals without aggregations and sorts:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF t_rec,
         col1 TYPE string,
         col2 TYPE string,
         col3 TYPE string,
         num  TYPE i,
         txt  TYPE string,
       END OF t_rec,
       tt_rec    TYPE TABLE OF t_rec WITH KEY primary_key COMPONENTS col1 col2 col3 txt,
       tt_refrec TYPE TABLE OF REF TO tt_rec WITH EMPTY KEY.

DATA(lt_outtab) = VALUE tt_rec( ( col1 = 'Prod' col2 = 'PL1' col3 = 'FAM1' num = 10 )
                                ( col1 = 'Prod' col2 = 'PL1' col3 = 'FAM1' num = 15 )
                                ( col1 = 'Prod' col2 = 'PL1' col3 = 'FAM2' num = 7  )
                                ( col1 = 'Prod' col2 = 'PL2' col3 = 'FAM1' num = 1  ) ).

DATA(lv_columns) = 3.
DATA(lv_subtotals) = ipow( base = 2 exp = lv_columns ).
DATA(lt_subtotals) = VALUE tt_refrec( ).

DO lv_subtotals TIMES.
  APPEND NEW #( ) TO lt_subtotals.
ENDDO.

LOOP AT lt_outtab ASSIGNING FIELD-SYMBOL(&amp;lt;ls_outtab&amp;gt;).
  DO lv_subtotals TIMES.
    DATA(lv_subtotal_index) = sy-index.
    DATA(ls_subtotal) = VALUE #( BASE &amp;lt;ls_outtab&amp;gt;
      txt = COND #( WHEN lv_subtotal_index = lv_subtotals THEN 'total' ELSE 'subtotal' ) ).

    DO lv_columns TIMES.
      DATA(lv_column_index) = sy-index.
      ASSIGN COMPONENT lv_column_index OF STRUCTURE ls_subtotal TO FIELD-SYMBOL(&amp;lt;ls_column&amp;gt;).

      DATA(lv_mask1) = CONV hex02( lv_subtotal_index - 1 ).
      DATA(lv_mask2) = CONV hex02( ipow( base = 2 exp = ( lv_columns - lv_column_index ) ) ).
      DATA(lv_test) =  CONV hex02( lv_mask1 BIT-AND lv_mask2 ).

      &amp;lt;ls_column&amp;gt; = COND string( WHEN lv_test IS INITIAL THEN &amp;lt;ls_column&amp;gt; ELSE space  ).
    ENDDO.

    ASSIGN lt_subtotals[ lv_subtotal_index ]-&amp;gt;* TO FIELD-SYMBOL(&amp;lt;lt_subtotals&amp;gt;).
    COLLECT ls_subtotal INTO &amp;lt;lt_subtotals&amp;gt;.
  ENDDO.
ENDLOOP.

LOOP AT lt_subtotals ASSIGNING FIELD-SYMBOL(&amp;lt;lr_subtotals&amp;gt;).
  APPEND LINES OF &amp;lt;lr_subtotals&amp;gt;-&amp;gt;* TO lt_outtab.
ENDLOOP.

cl_salv_table=&amp;gt;factory( IMPORTING r_salv_table = DATA(gr_table) CHANGING t_table = lt_outtab ).
gr_table-&amp;gt;display( ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here is the result:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Prod	PL1	FAM1	10	
Prod	PL1	FAM1	15	
Prod	PL1	FAM2	7	
Prod	PL2	FAM1	1	
Prod	PL1	FAM1	25	subtotal
Prod	PL1	FAM2	7	subtotal
Prod	PL2	FAM1	1	subtotal
Prod	PL1		32	subtotal
Prod	PL2		1	subtotal
Prod		FAM1	26	subtotal
Prod		FAM2	7	subtotal
Prod			33	subtotal
	PL1	FAM1	25	subtotal
	PL1	FAM2	7	subtotal
	PL2	FAM1	1	subtotal
	PL1		32	subtotal
	PL2		1	subtotal
		FAM1	26	subtotal
		FAM2	7	subtotal
			33	total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Apr 2021 10:46:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401998#M1995735</guid>
      <dc:creator>touzik_itc</dc:creator>
      <dc:date>2021-04-08T10:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: SALV - sorting and aggregation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401999#M1995736</link>
      <description>&lt;P&gt;Thank you &lt;SPAN class="mention-scrubbed"&gt;touzik_itc&lt;/SPAN&gt;, will try it&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 08:03:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/salv-sorting-and-aggregation/m-p/12401999#M1995736</guid>
      <dc:creator>Flavio</dc:creator>
      <dc:date>2021-04-09T08:03:42Z</dc:date>
    </item>
  </channel>
</rss>

