SALV Hierarchical Table 3 - Add Expand/Collapse Option

Posted by Krishh Webworld | 12:31 PM | , , | 0 comments »

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 List.

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 Snippet to get Expand / Collapse option
 *$*$*.....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.
DATA: lo_functions TYPE REF TO cl_salv_functions_list.

lo_functions = co_hs_alv->get_functions( ).
lo_functions->set_all( abap_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( 1 ).
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.
*
DATA: lo_level TYPE REF TO cl_salv_hierseq_level.
*
* Set items expanded by default
TRY.
lo_level = co_hs_alv->get_level( 1 ).
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:

0 comments

Archives

Subscribe Now: Feed Icon