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: 

Update cl_salv_tree after visibility of nodes has been changed

0 Kudos

Hi guys,

so I have this ALV-Tree as an instance of the cl_salv_tree class. I have integrated this into a dynpro via Custom Container. However the tree is supposed to switch between two views. This switch can be initiated by the user with a container button I implemented. In the backend the modification of the ALV-tree is then done by changing the visibility of the nodes present in the cl_salv_tree object according to the view the user chose.

My problem now is, I couldn't find a way to update/refresh the view of the ALV-tree with the changed visibility of the nodes.
Or basically I am asking how to dynamically change the visibility of nodes in cl_salv_tree and make these changes visible in the GUI.

Kind regards:)

6 REPLIES 6

Sandra_Rossi
Active Contributor

Does your action executes PAI/PBO? In that case, did you make sure to not re-instantiating the control? (cl_salv_tree instance)

0 Kudos

sandra.rossi Thank you for the answer ! I made sure the control is not being reinstatiated after the user presses the button to switch views.

Sandra_Rossi
Active Contributor
0 Kudos

Okay. Let me check. The time to create a minimal program...

Sandra_Rossi
Active Contributor
0 Kudos

Sorry, no issue at my side:

CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    METHODS pbo
      RAISING
        cx_salv_error.
  PRIVATE SECTION.
    DATA: salv   TYPE REF TO cl_salv_tree,
          scarrs TYPE STANDARD TABLE OF scarr.
    METHODS on_added_function
      FOR EVENT added_function
                  OF cl_salv_events_tree
      IMPORTING e_salv_function.
ENDCLASS.

CLASS lcl_app IMPLEMENTATION.
  METHOD pbo.
    IF salv IS NOT BOUND.
      cl_salv_tree=>factory( EXPORTING r_container = cl_gui_container=>screen0
                             IMPORTING r_salv_tree = salv
                             CHANGING  t_table     = scarrs ).
      DATA(lo_settings) = salv->get_tree_settings( ).
      lo_settings->set_hierarchy_size( 30 ).
      DATA(event) = salv->get_event( ).
      salv->get_functions( )->add_function( name = 'HIDE_FIRST_ROW' text = 'HIDE_FIRST_ROW' tooltip = '' position = 1 ).
      SET HANDLER on_added_function FOR event.
      SELECT * FROM scarr INTO TABLE @DATA(local_scarrs).
      LOOP AT local_scarrs REFERENCE INTO DATA(scarr).
        DATA(node) = salv->get_nodes( )->add_node(
          related_node = space " (root node)
          relationship = cl_gui_column_tree=>relat_last_child
          text         = |{ scarr->carrid } - { scarr->carrname }|
          data_row     = scarr->*
          folder       = abap_true ).
        salv->get_nodes( )->add_node(
          related_node = node->get_key( )
          relationship = cl_gui_column_tree=>relat_last_child
          text         = |test|
          folder       = abap_false ).
      ENDLOOP.
      salv->display( ).
    ENDIF.
    LOOP AT SCREEN.
      screen-active = '0'.
      MODIFY SCREEN.
    ENDLOOP.
  ENDMETHOD.
  METHOD on_added_function.
    IF e_salv_function = 'HIDE_FIRST_ROW'.
      salv->get_nodes( )->get_top_node( )->set_visible( value = abap_false )."expand( complete_subtree = abap_true ).
      salv->close_screen( ).
    ENDIF.
  ENDMETHOD.
ENDCLASS.

PARAMETERS dummy.

LOAD-OF-PROGRAM.
  DATA(app) = NEW lcl_app( ).

AT SELECTION-SCREEN OUTPUT.
  TRY.
      app->pbo( ).
    CATCH cx_root INTO DATA(lx).
      MESSAGE lx TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.

Thank you and apologize my delayed response.
Your answer was guiding me into the right direction. However in my case "close_screen()" didn't work, but calling "display()" instead did the job.

abo
Active Contributor

sandra.rossi I've tried your example both from the Java GUI and the Windows GUI.

Fun fact: on the Java GUI I have to click more than once on a random node after pressing the button before the first line is hidden but afterwards it won't trigger anymore.

On the 7.70 Windows GUI, however, each click on the button correctly hides the first row but it will also squeeze the secondary columns more and more until they're barely visible, weird.

No such effect with BCALV_TREE_04, but that one uses CL_GUI_ALV_TREE instead of CL_SALV_TREE.