Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Adding events to CL_GUI_ALV_TREE prevents expansion

matt
Active Contributor
657
*&---------------------------------------------------------------------*
*& Report zalv_tree
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zalv_tree.
CLASS lcl_main DEFINITION.
  PUBLIC SECTION.
    " Check out HANDLE_FAV_DROP in program BCALV_TREE_DND
    CLASS-METHODS class_constructor.
    METHODS:
      constructor,
      go
        RAISING
          cx_salv_error.
  PRIVATE SECTION.
    TYPES ty_tree_records TYPE STANDARD TABLE OF ztree_structure
                          WITH NON-UNIQUE KEY group count.
    DATA tree TYPE REF TO cl_gui_alv_tree.
    DATA actual_data TYPE ty_tree_records.
    DATA tree_records TYPE ty_tree_records.
    DATA groups TYPE string_table.
    DATA expanded_groups TYPE string_table.
    METHODS populate_tree.
    METHODS toggle_activation
      IMPORTING
        i_node_key TYPE any OPTIONAL
      RAISING
        cx_salv_msg.
    METHODS do_action
      IMPORTING
        i_node_key TYPE salv_de_node_key
      RAISING
        cx_salv_msg.
    METHODS delete_node
      IMPORTING
        i_leaf TYPE ztree_structure
      RAISING
        cx_salv_msg.
    METHODS on_double_click
        FOR EVENT item_double_click OF cl_gui_alv_tree
      IMPORTING
        node_key
        fieldname.
ENDCLASS.

CLASS lcl_main IMPLEMENTATION.
  METHOD constructor.
    actual_data = VALUE #( ( group = 'A' count = 1 active = abap_true )
                           ( group = 'A' count = 2 active = abap_true )
                           ( group = 'B' count = 1 active = abap_true )
                           ( group = 'B' count = 2 active = abap_true ) ).
    groups = VALUE #( ( `A` )
                      ( `B` ) ).
  ENDMETHOD.

  METHOD go.
    populate_tree( ).
  ENDMETHOD.

  METHOD populate_tree.
    IF tree IS NOT BOUND.
      DATA(dock) = NEW cl_gui_docking_container( repid = 'ZALV_TREE '
                                                 dynnr = '0100'
                                                 side  = cl_gui_docking_container=>dock_at_left ).
      dock->set_width( 1500 ).
      CLEAR tree_records.
      tree = NEW #( node_selection_mode   = cl_gui_column_tree=>node_sel_mode_single
                    parent                = dock
                    item_selection        = abap_true ).
*      tree->set_registered_events( 
*         EXPORTING events = VALUE #( ( eventid = cl_gui_column_tree=>eventid_item_double_click ) )
*         EXCEPTIONS cntl_error                = 1
*                    cntl_system_error         = 2
*                    illegal_event_combination = 3 ).
      SET HANDLER on_double_click FOR me->tree.
      DATA field_catalog TYPE lvc_t_fcat.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       = 'ZTREE_STRUCTURE'
        CHANGING
          ct_fieldcat            = field_catalog
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      field_catalog[ fieldname = 'GROUP' ]-no_out = abap_true.
      field_catalog[ fieldname = 'COUNT' ]-no_out = abap_true.
      DATA(header) = VALUE treev_hhdr( width = 10 ).
      me->tree->set_table_for_first_display( EXPORTING is_hierarchy_header = header
                                              CHANGING it_fieldcatalog     = field_catalog
                                                       it_outtab           = tree_records ).
    ENDIF.
    DATA initially_visible_nodes TYPE lvc_t_nkey.
    LOOP AT actual_data INTO DATA(actual_record).
      DATA parent TYPE lvc_nkey.
      AT NEW group.
        tree->add_node( EXPORTING
                        i_relat_node_key = ''
                        i_relationship   = cl_gui_column_tree=>relat_last_child
                        is_node_layout   = VALUE #( isfolder = abap_true expander = abap_true )
                        it_item_layout   = VALUE #( ( fieldname = 'GROUP'       
                                                      class = cl_gui_list_tree=>item_class_text )
                                                    ( fieldname = 'ACTION_ICON' 
                                                      class = cl_gui_list_tree=>item_class_text 
                                                      t_image = icon_create ) )
                        is_outtab_line   = VALUE ztree_structure( )
                        i_node_text      = CONV #( actual_record-group )
                        IMPORTING e_new_node_key = parent ).
        INSERT parent INTO TABLE initially_visible_nodes.
      ENDAT.
      tree->add_node( i_relat_node_key = parent
                      i_relationship   = cl_gui_column_tree=>relat_last_child
                      it_item_layout   = VALUE #( ( fieldname = 'COUNT'       
                                                    class = cl_gui_list_tree=>item_class_text )
                                                  ( fieldname = 'ACTION_ICON' 
                                                    class = cl_gui_list_tree=>item_class_text 
                                                    t_image = icon_delete )
                                                  ( fieldname = 'ACTIVE_ICON' 
                                                    class = cl_gui_list_tree=>item_class_text
                                                    t_image = SWITCH #( actual_record-active 
                                                        WHEN abap_true THEN icon_activate
                                                        ELSE icon_deactivate ) ) )
                      is_outtab_line   = VALUE ztree_structure( count = actual_record-count )
                      i_node_text      = CONV #( actual_record-count ) ).
    ENDLOOP.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    tree->ensure_nodes_visible(
      EXPORTING
        it_node_keys      = initially_visible_nodes
      EXCEPTIONS
        failed            = 1
        node_not_found    = 2
        cntl_system_error = 3
        OTHERS            = 4 ).
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    tree->frontend_update( ).
  ENDMETHOD.

  METHOD get_icon.
    DATA icon TYPE c LENGTH 255.
    CALL FUNCTION 'ICON_CREATE'
      EXPORTING
        name                  = i_icon
        add_stdinf            = space
      IMPORTING
        result                = icon
      EXCEPTIONS
        icon_not_found        = 0
        outputfield_too_short = 0
        OTHERS                = 0.
    r_result = icon.
  ENDMETHOD.

  METHOD on_double_click.
    TRY.
        CASE fieldname.
          WHEN 'ACTIVE_ICON'.
            toggle_activation( node_key ).
          WHEN 'ACTION_ICON'.
            do_action( node_key ).
          WHEN OTHERS.
            RETURN.
        ENDCASE.
      CATCH cx_salv_msg cx_salv_error INTO DATA(error).
        MESSAGE error TYPE 'I' DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.

  METHOD toggle_activation.
    DATA record_clicked_on TYPE ztree_structure.
    tree->get_outtab_line( EXPORTING i_node_key    = i_node_key
                           IMPORTING e_outtab_line =  record_clicked_on ).
    IF record_clicked_on-active = abap_true.
      record_clicked_on-active = abap_false.
      record_clicked_on-active_icon = _icons-inactive.
    ELSE.
      record_clicked_on-active = abap_true.
      record_clicked_on-active_icon = _icons-active.
    ENDIF.
    READ TABLE actual_data ASSIGNING FIELD-SYMBOL(<actual_line>)
                           WITH TABLE KEY group = record_clicked_on-group
                                          count = record_clicked_on-count.
    <actual_line>-active = record_clicked_on-active.
    tree->frontend_update( ).
  ENDMETHOD.

  METHOD do_action.
*    Not yet implemented
  ENDMETHOD.

  METHOD delete_node.
    DELETE actual_data WHERE group = i_leaf-group
                         AND count = i_leaf-count.
  ENDMETHOD.
ENDCLASS.

end-of-selection.
  CALL SCREEN 100.

MODULE status_0100 OUTPUT.
  NEW lcl_main( )->go( ).
ENDMODULE.

ZTREE_STRUCTURE is like this

Fieldname       Data Type    Length   Text
GROUP           STRING       0	       Group name
COUNT		INT4	     10	       Counter
ACTIVE		CHAR	     1	       Active
ACTIVE_ICON	CHAR	     80	       Active icon
ACTION_ICON	CHAR	     80	      Action icon

Screen 100 (nothing on it) has pbo

PROCESS BEFORE OUTPUT.
  MODULE STATUS_0100.
PROCESS AFTER INPUT.
<br>

This runs, and display the tree and columns nicely. As soon as I uncomment the set_registered_events methods, the leaves are no longer displayed.

Any ideas? (This is the first time I've used this control! After 20+ years of ABAP...!)

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
464

Found the problem. SAP already registers the Expand event, so you should append your events:

      tree->get_registered_events(
        IMPORTING
          events     = data(events)
        EXCEPTIONS
          cntl_error = 1
          others     = 2 ).
      IF sy-subrc <> 0.
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      tree->set_registered_events(
         EXPORTING events = VALUE #( base events ( eventid = cl_gui_column_tree=>eventid_item_double_click ) )
         EXCEPTIONS cntl_error                = 1
                    cntl_system_error         = 2
                    illegal_event_combination = 3 ).
3 REPLIES 3

Sandra_Rossi
Active Contributor
465

Found the problem. SAP already registers the Expand event, so you should append your events:

      tree->get_registered_events(
        IMPORTING
          events     = data(events)
        EXCEPTIONS
          cntl_error = 1
          others     = 2 ).
      IF sy-subrc <> 0.
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      tree->set_registered_events(
         EXPORTING events = VALUE #( base events ( eventid = cl_gui_column_tree=>eventid_item_double_click ) )
         EXCEPTIONS cntl_error                = 1
                    cntl_system_error         = 2
                    illegal_event_combination = 3 ).

0 Kudos
464

For information, full reproducible example (just copy/paste/run it):

CLASS lcl_main DEFINITION.
  PUBLIC SECTION.
    " Check out HANDLE_FAV_DROP in program BCALV_TREE_DND
    METHODS:
      constructor,
      go
        RAISING
          cx_salv_error.
  PRIVATE SECTION.
    TYPES: BEGIN OF ztree_structure,
             group       TYPE string,
             count       TYPE int4,
             active      TYPE c LENGTH 1,
             active_icon TYPE c LENGTH 80,
             action_icon TYPE c LENGTH 80,
           END OF ztree_structure.
    TYPES ty_tree_records TYPE STANDARD TABLE OF ztree_structure
                          WITH NON-UNIQUE KEY group count.
    DATA tree TYPE REF TO cl_gui_alv_tree.
    DATA actual_data TYPE ty_tree_records.
    DATA tree_records TYPE ty_tree_records.
    DATA groups TYPE string_table.
    DATA expanded_groups TYPE string_table.
    METHODS populate_tree.
    METHODS toggle_activation
      IMPORTING
        i_node_key TYPE any OPTIONAL
      RAISING
        cx_salv_msg.
    METHODS do_action
      IMPORTING
        i_node_key TYPE salv_de_node_key
      RAISING
        cx_salv_msg.
    METHODS delete_node
      IMPORTING
        i_leaf TYPE ztree_structure
      RAISING
        cx_salv_msg.
    METHODS on_double_click
          FOR EVENT item_double_click OF cl_gui_alv_tree
      IMPORTING
          node_key
          fieldname.
ENDCLASS.

CLASS lcl_main IMPLEMENTATION.
  METHOD constructor.
    actual_data = VALUE #( ( group = 'A' count = 1 active = abap_true )
                           ( group = 'A' count = 2 active = abap_true )
                           ( group = 'B' count = 1 active = abap_true )
                           ( group = 'B' count = 2 active = abap_true ) ).
    groups = VALUE #( ( `A` )
                      ( `B` ) ).
  ENDMETHOD.

  METHOD go.
    populate_tree( ).
  ENDMETHOD.

  METHOD populate_tree.
    IF tree IS NOT BOUND.
      DATA(dock) = NEW cl_gui_docking_container( repid = sy-repid "'ZALV_TREE '
                                                 dynnr = sy-dynnr "'0100'
                                                 side  = cl_gui_docking_container=>dock_at_left ).
      dock->set_width( 1500 ).
      CLEAR tree_records.
      tree = NEW #( node_selection_mode   = cl_gui_column_tree=>node_sel_mode_single
                    parent                = dock
                    item_selection        = abap_true ).
      tree->get_registered_events(
        IMPORTING
          events     = DATA(events)
        EXCEPTIONS
          cntl_error = 1
          OTHERS     = 2 ).
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      tree->set_registered_events(
         EXPORTING events = VALUE #( BASE events ( eventid = cl_gui_column_tree=>eventid_item_double_click ) )
         EXCEPTIONS cntl_error                = 1
                    cntl_system_error         = 2
                    illegal_event_combination = 3 ).
      SET HANDLER on_double_click FOR me->tree.
      DATA field_catalog TYPE lvc_t_fcat.
      PERFORM get_fcat USING tree_records CHANGING field_catalog.
      field_catalog[ fieldname = 'GROUP' ]-no_out = abap_true.
      field_catalog[ fieldname = 'COUNT' ]-no_out = abap_true.
      DATA(header) = VALUE treev_hhdr( width = 10 ).
      me->tree->set_table_for_first_display( EXPORTING is_hierarchy_header = header
                                              CHANGING it_fieldcatalog     = field_catalog
                                                       it_outtab           = tree_records ).
    ENDIF.
    DATA initially_visible_nodes TYPE lvc_t_nkey.
    LOOP AT actual_data INTO DATA(actual_record).
      DATA parent TYPE lvc_nkey.
      AT NEW group.
        tree->add_node( EXPORTING
                        i_relat_node_key = ''
                        i_relationship   = cl_gui_column_tree=>relat_last_child
                        is_node_layout   = VALUE #( isfolder = abap_true expander = abap_true )
                        it_item_layout   = VALUE #( ( fieldname = 'GROUP'
                                                      class = cl_gui_list_tree=>item_class_text )
                                                    ( fieldname = 'ACTION_ICON'
                                                      class = cl_gui_list_tree=>item_class_text
                                                      t_image = icon_create ) )
                        is_outtab_line   = VALUE ztree_structure( )
                        i_node_text      = CONV #( actual_record-group )
                        IMPORTING e_new_node_key = parent ).
        INSERT parent INTO TABLE initially_visible_nodes.
      ENDAT.
      tree->add_node( i_relat_node_key = parent
                      i_relationship   = cl_gui_column_tree=>relat_last_child
                      it_item_layout   = VALUE #( ( fieldname = 'COUNT'
                                                    class = cl_gui_list_tree=>item_class_text )
                                                  ( fieldname = 'ACTION_ICON'
                                                    class = cl_gui_list_tree=>item_class_text
                                                    t_image = icon_delete )
                                                  ( fieldname = 'ACTIVE_ICON'
                                                    class = cl_gui_list_tree=>item_class_text
                                                    t_image = SWITCH #( actual_record-active
                                                        WHEN abap_true THEN icon_activate
                                                        ELSE icon_deactivate ) ) )
                      is_outtab_line   = VALUE ztree_structure( count = actual_record-count )
                      i_node_text      = CONV #( actual_record-count ) ).
    ENDLOOP.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    tree->frontend_update( ).
  ENDMETHOD.

  METHOD on_double_click.
  ENDMETHOD.

  METHOD toggle_activation.
  ENDMETHOD.

  METHOD do_action.
  ENDMETHOD.

  METHOD delete_node.
    DELETE actual_data WHERE group = i_leaf-group
                         AND count = i_leaf-count.
  ENDMETHOD.
ENDCLASS.

PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  NEW lcl_main( )->go( ).

FORM get_fcat CHANGING it_std TYPE STANDARD TABLE et_fcat TYPE lvc_t_fcat.
  DATA lo_table TYPE REF TO cl_salv_table.
  DATA lo_columns TYPE REF TO cl_salv_columns_list.
  DATA lo_agg TYPE REF TO cl_salv_aggregations.
  REFRESH et_fcat.
  CALL METHOD cl_salv_table=>factory
    IMPORTING
      r_salv_table = lo_table
    CHANGING
      t_table      = it_std[].
  lo_columns = lo_table->get_columns( ).
  lo_agg = lo_table->get_aggregations( ).
  et_fcat = cl_salv_controller_metadata=>get_lvc_fieldcatalog( r_columns = lo_columns r_aggregations = lo_agg ).
ENDFORM.

matt
Active Contributor
0 Kudos
464

Perfect. Thank you.

Here's the full working (ish, there's still errors in functionality, but adding nodes and deleting nodes works) code for anyone finding this question.

REPORT zalv_tree.
CLASS lcl_main DEFINITION.
  PUBLIC SECTION.
    METHODS:
      constructor,
      go
        RAISING
          cx_salv_error.
  PRIVATE SECTION.
    TYPES ty_tree_records TYPE STANDARD TABLE OF ztree_structure
                          WITH NON-UNIQUE KEY group count.
    DATA tree TYPE REF TO cl_gui_alv_tree.
    DATA actual_data TYPE ty_tree_records.
    DATA tree_records TYPE ty_tree_records.
    METHODS populate_tree.
    METHODS toggle_activation
      IMPORTING
        i_node_key TYPE any OPTIONAL
      RAISING
        cx_salv_msg.
    METHODS do_action
      IMPORTING
        i_node_key TYPE salv_de_node_key
      RAISING
        cx_salv_msg.
    METHODS delete_node
      IMPORTING
        i_node_key TYPE salv_de_node_key
        i_leaf     TYPE ztree_structure
      RAISING
        cx_salv_msg.
    METHODS create_node
      IMPORTING
        i_node_key TYPE salv_de_node_key
        i_group    TYPE string.
    METHODS on_double_click
        FOR EVENT item_double_click OF cl_gui_alv_tree
      IMPORTING
        node_key
        fieldname.
ENDCLASS.

CLASS lcl_main IMPLEMENTATION.
  METHOD constructor.
    actual_data = VALUE #( ( group = 'A' )
                           ( group = 'A' count = 1 active = abap_true )
                           ( group = 'A' count = 2 active = abap_true )
                           ( group = 'B' )
                           ( group = 'B' count = 1 active = abap_true )
                           ( group = 'B' count = 2 active = abap_true ) ).
  ENDMETHOD.

  METHOD go.
    populate_tree( ).
  ENDMETHOD.

  METHOD populate_tree.
    IF tree IS NOT BOUND.
      DATA(dock) = NEW cl_gui_docking_container( repid = 'ZALV_TREE '
                                                 dynnr = '0100'
                                                 side  = cl_gui_docking_container=>dock_at_left ).
      dock->set_width( 1500 ).
      CLEAR tree_records.
      tree = NEW #( node_selection_mode   = cl_gui_column_tree=>node_sel_mode_single
                    parent                = dock
                    item_selection        = abap_true ).
      tree->get_registered_events(
         IMPORTING
           events     = DATA(events)
         EXCEPTIONS
           cntl_error = 1
           OTHERS     = 2 ).
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      tree->set_registered_events(
         EXPORTING events = VALUE #( BASE events ( eventid = cl_gui_column_tree=>eventid_item_double_click ) )
         EXCEPTIONS cntl_error                = 1
                    cntl_system_error         = 2
                    illegal_event_combination = 3 ).
      SET HANDLER on_double_click FOR me->tree.
      DATA field_catalog TYPE lvc_t_fcat.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       = 'ZTREE_STRUCTURE'
        CHANGING
          ct_fieldcat            = field_catalog
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      field_catalog[ fieldname = 'GROUP' ]-no_out = abap_true.
      field_catalog[ fieldname = 'COUNT' ]-no_out = abap_true.
      DATA(header) = VALUE treev_hhdr( width = 10 ).
      me->tree->set_table_for_first_display( EXPORTING is_hierarchy_header = header
                                              CHANGING it_fieldcatalog     = field_catalog
                                                       it_outtab           = tree_records ).
    ENDIF.
    DATA initially_visible_nodes TYPE lvc_t_nkey.
    LOOP AT actual_data INTO DATA(actual_record).
      DATA parent TYPE lvc_nkey.
      IF actual_record-count EQ 0.
        tree->add_node( EXPORTING
                        i_relat_node_key = ''
                        i_relationship   = cl_gui_column_tree=>relat_last_child
                        is_node_layout   = VALUE #( isfolder = abap_true expander = abap_true )
                        it_item_layout   = VALUE #( ( fieldname = 'GROUP'       class = cl_gui_list_tree=>item_class_text )
                                                    ( fieldname = 'ACTION_ICON' class = cl_gui_list_tree=>item_class_text t_image = icon_create ) )
                        is_outtab_line   = VALUE ztree_structure( )
                        i_node_text      = CONV #( actual_record-group )
                        IMPORTING e_new_node_key = parent ).
        INSERT parent INTO TABLE initially_visible_nodes.
      ELSE.
        tree->add_node( i_relat_node_key = parent
                        i_relationship   = cl_gui_column_tree=>relat_last_child
                        it_item_layout   = VALUE #( ( fieldname = 'COUNT'       class = cl_gui_list_tree=>item_class_text )
                                                    ( fieldname = 'ACTION_ICON' class = cl_gui_list_tree=>item_class_text t_image = icon_delete )
                                                    ( fieldname = 'ACTIVE_ICON' class = cl_gui_list_tree=>item_class_text
                                                      t_image = SWITCH #( actual_record-active WHEN abap_true THEN icon_activate
                                                                                                              ELSE icon_deactivate ) ) )
                        is_outtab_line   = VALUE ztree_structure( group = actual_record-group count = actual_record-count )
                        i_node_text      = CONV #( actual_record-count ) ).
      ENDIF.
    ENDLOOP.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    tree->ensure_nodes_visible(
      EXPORTING
        it_node_keys      = initially_visible_nodes
      EXCEPTIONS
        failed            = 1
        node_not_found    = 2
        cntl_system_error = 3
        OTHERS            = 4 ).
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    tree->frontend_update( ).
  ENDMETHOD.

  METHOD on_double_click.
    TRY.
        CASE fieldname.
          WHEN 'ACTIVE_ICON'.
            toggle_activation( node_key ).
          WHEN 'ACTION_ICON'.
            do_action( node_key ).
          WHEN OTHERS.
            RETURN.
        ENDCASE.
        tree->frontend_update( ).
      CATCH cx_salv_msg INTO DATA(error).
        MESSAGE error TYPE 'I' DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.

  METHOD toggle_activation.
    DATA record_clicked_on TYPE ztree_structure.
    tree->get_outtab_line( EXPORTING i_node_key    = i_node_key
                           IMPORTING e_outtab_line =  record_clicked_on ).
    READ TABLE actual_data ASSIGNING FIELD-SYMBOL(<actual_line>)
                           WITH TABLE KEY group = record_clicked_on-group
                                          count = record_clicked_on-count.
    DATA icon TYPE icon_l2.
    IF <actual_line>-active = abap_true.
      record_clicked_on-active = abap_false.
      icon = icon_deactivate.
    ELSE.
      record_clicked_on-active = abap_true.
      icon = icon_activate.
    ENDIF.
    <actual_line>-active = record_clicked_on-active.
    tree->change_node( i_node_key     = i_node_key
                       i_outtab_line  = <actual_line>
                       it_item_layout = VALUE #( ( fieldname = 'ACTION_ICON'
                                                   t_image   = icon_delete
                                                   u_t_image =  abap_true )
                                                 ( fieldname = 'ACTIVE_ICON'
                                                   t_image   = icon
                                                   u_t_image =  abap_true ) ) ).
  ENDMETHOD.

  METHOD do_action.
    DATA record_clicked_on TYPE ztree_structure.
    tree->get_outtab_line( EXPORTING i_node_key    = i_node_key
                           IMPORTING e_outtab_line =  record_clicked_on ).
    IF record_clicked_on-count IS INITIAL.
      create_node( i_node_key = i_node_key i_group = record_clicked_on-group ).
    ELSE.
      delete_node( i_node_key = i_node_key i_leaf = record_clicked_on ).
    ENDIF.
  ENDMETHOD.

  METHOD delete_node.
    DELETE actual_data WHERE group = i_leaf-group
                         AND count = i_leaf-count.
    tree->delete_subtree( i_node_key ).
  ENDMETHOD.

  METHOD create_node.
    DATA(new_record) = VALUE ztree_structure( group = i_group
                                              count = 0
                                              active = abap_false ).
    DO.
      new_record-count = new_record-count + 1.
      CHECK NOT line_exists( actual_data[ group = i_group count = new_record-count ] ).
      EXIT.
    ENDDO.
    INSERT new_record INTO TABLE actual_data.
    tree->add_node( i_relat_node_key = i_node_key
              i_relationship   = cl_gui_column_tree=>relat_last_child
              it_item_layout   = VALUE #( ( fieldname = 'COUNT'       class = cl_gui_list_tree=>item_class_text )
                                          ( fieldname = 'ACTION_ICON' class = cl_gui_list_tree=>item_class_text t_image = icon_delete )
                                          ( fieldname = 'ACTIVE_ICON' class = cl_gui_list_tree=>item_class_text
                                            t_image = icon_deactivate ) )
              is_outtab_line   = new_record
              i_node_text      = CONV #( new_record-count ) ).
    tree->expand_node( i_node_key ).
  ENDMETHOD.
ENDCLASS.

end-of-selection.
  CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  NEW lcl_main( )->go( ).
ENDMODULE.