Skip to Content

Display only subtotal and totals only in alv report using cl_salv

Hello Experts,

I build an ALV report to show the output as shown as below.

Here i want to display only subtotals and totals i.e, not an item details, without user intervention. as shown as below.

How to achieve the above output.

any suggestions please..?

actual-op.png (5.5 kB)
expected-op.png (4.3 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Feb 27, 2019 at 02:27 PM

    Try this:

    report zdummy.
    
    start-of-selection.
      perform start_of_selection.
    
    form start_of_selection.
    
      types begin of lty_data.
      types column1 type char30.
      types column2 type char30.
      types column3 type i.
      types end   of lty_data.
    
      types lty_data_tt type standard table of lty_data with empty key.
    
      data(lt_data)
          = value lty_data_tt(
            ( column1 = 'Column1Value1' column2 = 'Column2Value1' column3 = 1 )
            ( column1 = 'Column1Value1' column2 = 'Column2Value1' column3 = 2 )
            ( column1 = 'Column1Value1' column2 = 'Column2Value1' column3 = 3 )
            ( column1 = 'Column1Value1' column2 = 'Column2Value2' column3 = 4 )
            ( column1 = 'Column1Value1' column2 = 'Column2Value2' column3 = 5 )
            ( column1 = 'Column1Value1' column2 = 'Column2Value2' column3 = 6 )
            ( column1 = 'Column1Value1' column2 = 'Column2Value2' column3 = 7 )
            ( column1 = 'Column1Value2' column2 = 'Column2Value3' column3 = 8 )
            ( column1 = 'Column1Value2' column2 = 'Column2Value3' column3 = 9 )
            ( column1 = 'Column1Value2' column2 = 'Column2Value3' column3 = 10 )
            ( column1 = 'Column1Value2' column2 = 'Column2Value4' column3 = 11 )
            ( column1 = 'Column1Value2' column2 = 'Column2Value4' column3 = 12 )
            ( column1 = 'Column1Value2' column2 = 'Column2Value4' column3 = 13 )
            ( column1 = 'Column1Value2' column2 = 'Column2Value4' column3 = 14 )
            ( column1 = 'Column1Value3' column2 = 'Column2Value5' column3 = 15 )
            ( column1 = 'Column1Value3' column2 = 'Column2Value5' column3 = 16 )
            ( column1 = 'Column1Value3' column2 = 'Column2Value5' column3 = 17 )
            ( column1 = 'Column1Value3' column2 = 'Column2Value5' column3 = 18 )
            ( column1 = 'Column1Value3' column2 = 'Column2Value6' column3 = 19 )
            ( column1 = 'Column1Value3' column2 = 'Column2Value6' column3 = 20 )
            ( column1 = 'Column1Value3' column2 = 'Column2Value6' column3 = 21 )
          ).
    
      cl_salv_table=>factory(
        importing
          r_salv_table   = data(lr_salv_table)    " Basis Class Simple ALV Tables
        changing
          t_table        = lt_data
      ).
    
      lr_salv_table->get_functions( )->set_all( value = if_salv_c_bool_sap=>true ).
    
      lr_salv_table->get_layout( )->set_save_restriction( value = if_salv_c_layout=>restrict_none ).
    
      lr_salv_table->get_sorts( )->add_sort(
        exporting
          columnname         = 'COLUMN1'    " ALV Control: Field Name of Internal Table Field
          position           = 1
          sequence           = if_salv_c_sort=>sort_up    " Sort Sequence
          subtotal           = if_salv_c_bool_sap=>true    " Boolean Variable (X=True, Space=False)
      ).
    
      lr_salv_table->get_sorts( )->add_sort(
        exporting
          columnname         = 'COLUMN2'    " ALV Control: Field Name of Internal Table Field
          position           = 2
          sequence           = if_salv_c_sort=>sort_up    " Sort Sequence
          subtotal           = if_salv_c_bool_sap=>true    " Boolean Variable (X=True, Space=False)
      ).
    
      lr_salv_table->get_aggregations( )->add_aggregation(
        exporting
          columnname         = 'COLUMN3'    " ALV Control: Field Name of Internal Table Field
          aggregation        = if_salv_c_aggregation=>total    " Aggregation
      ).
    
      lr_salv_table->get_sorts( )->set_compressed_subtotal( value = 'COLUMN2' ).
    
      lr_salv_table->display( ).
    
    endform.
    
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.