SALV Hierarchical Table 3 – Add Expand/Collapse Option

By | October 8, 2008 | SALV HS, SALV Tutorial, Tutorials | 18,452 | 0

Today in the series of the SALV Hiearchical list display, we will see how to add the Expand/Collapse button in the Hierarchical ALV. All discussion related to the Hierarchical table display can be found under Tutorials > SALV HS Display .

Expand/Collapse button will provide an option to users to only see the Header List. By selecting the expand button, it will show both Header and detail List. By selecting the same button again it will collapse the list and gives only the header list.

Here is the code Snippet which provides the ADD-ON code. This ADD-ON code can be replaced with the relevent section from this code snippet in the base program. You can find the base program code snippet in the post SALV Hierarchical Table 1 – Simple table display. Adding code to base program is like adding the code correction from the OSS Note. Additionally, we will always include the default PF-status in all the code snippet.

UML diagram for the application would be like:

Code snippet to get the Expand / Collapse option in Hierarchical ALV.

*$*$*.....CODE_ADD_1 - Begin..................................1..*$*$*
*
*    In this section we will define the private methods which can
*      be implemented to set the properties of the ALV and can be
*      called in the GENERATE_OUTPUT method
*
  PRIVATE SECTION.
    METHODS:
      set_default_pf
        CHANGING
          co_hs_alv TYPE REF TO cl_salv_hierseq_table.
*
    METHODS:
      set_expand_option
        CHANGING
          co_hs_alv TYPE REF TO cl_salv_hierseq_table.
*$*$*.....CODE_ADD_1 - End....................................1..*$*$*
*
*
*$*$*.....CODE_ADD_2 - Begin..................................2..*$*$*
*
*    In this area we will call the methods which will set the
*      different properties to the ALV
*
*   Default PF status
    CALL METHOD me->set_default_pf
      CHANGING
        co_hs_alv o_hs_alv.
*
*   Expand Option
    CALL METHOD me->set_expand_option
      CHANGING
        co_hs_alv o_hs_alv.
*$*$*.....CODE_ADD_2 - End....................................2..*$*$*
*
*
*$*$*.....CODE_ADD_3 - Begin..................................3..*$*$*
*
*    In this area we will implement the methods which are defined in
*      the class definition
*
  METHOD set_default_pf.
    DATAlo_functions TYPE REF TO cl_salv_functions_list.
    lo_functions co_hs_alv->get_functions).
    lo_functions->set_allabap_true ).
  ENDMETHOD.                    "set_default_pf
*
  METHOD set_expand_option.
*
    DATA:
      lo_columns TYPE REF TO cl_salv_columns_hierseq.
*
*   Get the Columns of the Master
    TRY.
        lo_columns co_hs_alv->get_columns).
      CATCH cx_salv_not_found.
    ENDTRY.
*
*   set expand column
    TRY.
        lo_columns->set_expand_column'EXPAND' ).
      CATCH cx_salv_data_error.                         "#EC NO_HANDLER
    ENDTRY.
*
    DATAlo_level TYPE REF TO cl_salv_hierseq_level.
*
*   Set items expanded by default
    TRY.
        lo_level co_hs_alv->get_level).
        lo_level->set_items_expanded).
      CATCH cx_salv_not_found.
    ENDTRY.
*
  ENDMETHOD.                    "set_expand_option
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*

This code will generate output like:

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 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 274 articles.

Load comments

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.