SALV Table 19 – Columns Specific Grouping

By | July 20, 2014 | SALV Table, SALV Tutorial | 6,154 | 5

Specific Groups on the ABAP SALV would help users to easily find the columns in the display setting variants. Lets check it out how you can achieve it.

What is Columns Specific Grouping

When you have so many fields in the ALV output, it becomes very difficult for the users to look for the specific field in the Change Layout function. It becomes more confusing when you have same set of columns – like 12 columns for Budget Amount (each for 12 period) and another 12 columns for Actual Amount.

In this instance when you define the column grouping, users would be able to easily choose specific group and the available columns on the left side would be filtered by the value.

So, when you have Specific Group implemented, you would notice this selection in the Variant > Change Layout popup in the ALV output

When you don’t have the specific group implemented the ALV, you will not see this option:

Availability of the class CL_SALV_SPECIFIC_GROUPS

The Class CL_SALV_SPECIFIC_GROUPS is available from ECC6 Ehp4. So, this functionality will not work in the prior versions. Related methods are also available from the release. Main methods are:

  • Method GET_SPECIFIC_GROUPS in class CL_SALV_FUNCTIONAL_SETTINGS
  • Method SET_SPECIFIC_GROUP in class CL_SALV_COLUMN_LIST

Achieve using ABAP SALV OM

To be able to achieve the specific groups, you need to follow these steps when you are designing ALV using SALV OM:

  1. Get the Functional Settings Object from the SALV object using method GET_FUNCTIONAL_SETTINGS( )
  2. Get the Specific Group object from the Functional Settings object GET_SPECIFIC_GROUPS( )
  3. Create Various different Groups IDs ADD_SPECIFIC_GROUP( )
  4. Get Columns Objects GET_COLUMNS( )
  5. For each column where Group needs to be set, set the created group ID SET_SPECIFIC_GROUP( )

Code Lines

Here is the program

 
REPORT znp_np_salv_column_spec_group.
 
*----------------------------------------------------------------------*
*       CLASS lcl_report DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
*
  PUBLIC SECTION.
    DATA: t_data TYPE STANDARD TABLE OF faglflext.
    DATA: o_salv TYPE REF TO cl_salv_table.
 
    METHODS:
      get_data,
      set_column_specific_group,
      generate_output.
ENDCLASS.                    "lcl_report DEFINITION
*
*
START-OF-SELECTION.
  DATA: lo_report TYPE REF TO lcl_report.
  CREATE OBJECT lo_report.
  lo_report->get_data( ).
  lo_report->generate_output( ).
 
*----------------------------------------------------------------------*
*       CLASS lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
  METHOD get_data.
*   data selection
    SELECT * FROM faglflext
      INTO TABLE t_data
      UP TO 20 ROWS.
 
  ENDMETHOD.                    "get_data
*
*.......................................................................
  METHOD generate_output.
    DATA: lo_msg TYPE REF TO cx_salv_msg.
    TRY.
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table = o_salv
          CHANGING
            t_table      = t_data ).
      CATCH cx_salv_msg INTO lo_msg.
    ENDTRY.
 
    DATA: lo_functions TYPE REF TO cl_salv_functions_list.
    lo_functions = o_salv->get_functions( ).
    lo_functions->set_all( abap_true ).
 
    me->set_column_specific_group( ).
 
* Displaying the ALV
    o_salv->display( ).
  ENDMETHOD.                    "generate_output
*
  METHOD set_column_specific_group.
 
*----
*   create the Groups
*----
    DATA: lo_functional_settings  TYPE REF TO cl_salv_functional_settings,
          lo_specific_groups      TYPE REF TO cl_salv_specific_groups,
          lv_text                 TYPE cl_salv_specific_groups=>y_text.
 
    lo_functional_settings = o_salv->get_functional_settings( ).
    lo_specific_groups = lo_functional_settings->get_specific_groups( ).
 
* Group for column which start with HSL, as group ID GRP1
    TRY.
        lv_text = 'HSL Amounts'.
        lo_specific_groups->add_specific_group( id   = 'GRP1'
                                                text = lv_text ).
      CATCH cx_salv_existing.                           "#EC NO_HANDLER
    ENDTRY.
* Group for column which start with TSL, as group ID GRP2
    TRY.
        lv_text = 'TSL Amounts'.
        lo_specific_groups->add_specific_group( id   = 'GRP2'
                                                text = lv_text ).
      CATCH cx_salv_existing.                           "#EC NO_HANDLER
    ENDTRY.
 
 
*----
*   Assign the group to columns
*----
    DATA: lo_columns  TYPE REF TO cl_salv_columns_table,
          lo_column   TYPE REF TO cl_salv_column_list,
          lt_cols     TYPE        salv_t_column_ref,
          ls_cols     LIKE LINE OF lt_cols.
 
 
    lo_columns = o_salv->get_columns( ).
    lt_cols    = lo_columns->get( ).
    TRY.
        lo_column ?= lo_columns->get_column( 'MANDT' ).
        lo_column->set_technical( if_salv_c_bool_sap=>true ).
      CATCH cx_salv_not_found.                          "#EC NO_HANDLER
    ENDTRY.
 
    LOOP AT lt_cols INTO ls_cols.
      lo_column ?= ls_cols-r_column.    "Narrow casting
      CASE ls_cols-columnname+0(3).
" GRP1 to HSL columns
        WHEN 'HSL'.
          lo_column->set_specific_group( id = 'GRP1' ).
          lo_column->set_visible( " ).
" GRP2 to TSL columns
        WHEN 'TSL'.
          lo_column->set_specific_group( id = 'GRP2' ).
          lo_column->set_visible( " ).
      ENDCASE.
    ENDLOOP.
 
 
  ENDMETHOD.                    "set_column_specific_group
 
ENDCLASS.                    "lcl_report IMPLEMENTATION
 

Output

So, when you have the Specific group implemented, you would be able to see the groups like this

When you change the group, you would only see the columns selected by group, Easy for users to find the columns they are looking for :)

Links

Read more on Grouping Fields for Field Selection

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{273 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 273 articles.

Load comments

5 Comments

  • carsten

    Hi Naimesh,

    that’s a nice one, thanks for this!

    As far as i can see, it’s not possible to put filds into multiple groups. Or is ther a trick to do so?

    Thanks & Cheers
    carsten

  • Aaron

    This is a great tip/feature. However, you should do your users a favor and ensure each field has unique selection text and column text. With that said, I can see myself using this for reports that go across AP and AR or any other report that goes across modules/fences/documents/etc… and have a large list of fields.

  • Hello Carsten – I don’t see any possibility to have the same column in different groups. The Group set using the SET_SPECIFIC_GROUP would be mapped to the SP_GROUP field of the Field Catalog. Since the SP_GROUP is not a table, it would only accept one value.

    Hello Aaaron – I agree that you must have unique description for each field :) In the report with many columns in the output, the columns come from many different sources. Grouping those columns would make user’s life easier. Like a Sales report, where grouping on Material, price, etc for Sales order, Delivery and billing document.

    Thanks,
    Naimesh Patel

  • Carsten

    Hi Naimesh,

    you can use this functionality also in FuMo REUSE_ALV_GRID_DISPLAY_LVC

    Parameter
    IT_SPECIAL_GROUPS_LVC (TYPE LVC_T_SGRP)

    The link goes with LVC_S_FCAT-SP_GROUP of the field catalogue IT_FIELDCAT_LVC

    Cheers
    carsten

  • Hello Carsten,

    Yes, the functionality is long available in ALV Grid by CL_GUI_ALV_GRID and the REUSE_ FMs. It was not integrated in SALV model till EhP6. I guess SALV model is catching up ;)

    Thanks,
    Naimesh Patel

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.