Activate user interaction within SAP ALV tree

Insert the following code into the PBO of the screen after the ALV tree has been created to initiate it and activate it for user interaction.

i.e after 'CALL METHOD gd_tree->set_table_for_first_display' has been executed.

*&-------------------------------------------------------------*
*&      REGISTER_EVENTS
*&-------------------------------------------------------------*
* define the events which will be passed to the backend
  data: lt_events type cntl_simple_events,
        l_event type cntl_simple_event.
* define the events which will be passed to the backend
  l_event-eventid = cl_gui_column_tree=>eventid_expand_no_children.
  append l_event to lt_events.
  l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
  append l_event to lt_events.
  l_event-eventid = cl_gui_column_tree=>eventid_header_context_men_req.
  append l_event to lt_events.
  l_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
  append l_event to lt_events.
  l_event-eventid = cl_gui_column_tree=>eventid_item_context_menu_req.
  append l_event to lt_events.
  l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.
  append l_event to lt_events.
  l_event-eventid = cl_gui_column_tree=>eventid_header_click.
  append l_event to lt_events.
  l_event-eventid = cl_gui_column_tree=>eventid_item_keypress.
  append l_event to lt_events.
  call method gd_tree->set_registered_events
    exporting
      events = lt_events
    exceptions
      cntl_error                = 1
      cntl_system_error         = 2
      illegal_event_combination = 3.
  if sy-subrc <> 0.
    message x208(00) with 'ERROR'.                       "#EC NOTEXT
  endif.
* set Handler
  data: l_event_receiver type ref to lcl_tree_event_receiver.
  create object l_event_receiver.
  set handler l_event_receiver->handle_node_ctmenu_request
                                                        for gd_tree.
  set handler l_event_receiver->handle_node_ctmenu_selected
                                                        for gd_tree.
  set handler l_event_receiver->handle_item_ctmenu_request
                                                        for gd_tree.
  set handler l_event_receiver->handle_item_ctmenu_selected
                                                        for gd_tree.
  set handler l_event_receiver->handle_item_double_click
                                                        for gd_tree.
  set handler l_event_receiver->handle_header_click
                                                        for gd_tree.

Related Articles

Add button to SAP ALV tree toolbar using ABAP code
ABAP ALV Tree tutorial to create a fully working ALVTree Control SAP dynpro program
Create ALV Tree Custom control and add to sap dynpro screen
Final ABAP code for the ALV Tree PBO(..O01) and FORM(..F01) includes
Create SAP ALV Tree Container in ABAP dynpro screen container
Create Container and Object
Create ALV tree main program including Data & Event declaration
SAP ALV Tree fieldcatalog creation
Set SAP ALV tree table for first display and user interaction
Build SAP ALV tree Hierarchy
Build SAP ALV tree Hierarchy Header
Add alv tree already exists check to pbo module
Create all includes required for the ALV tree report
Full ABAP code listing of main ALV tree program
Module creation screen
Create SAP ALV Tree object within ABAP dynpro screen container/H1>
Create ok code to store ALV tree user interaction
Example Output from ALV tree display
Create screen control
Create Screen along with PBO and PAI modules
Create Pf-status(screen menu functionality)
Refresh ALVtree
Build Report Header(Title)
ALVtree toolbar processing
Implement user defined buttons to ALVtree toolbar
ALVtree user interaction processing
Implement ALVtree user interaction processing
Setup ALVtree variant
Main Steps to create ALV simple Tree(Using Objects)
Create Add Custom control to screen
Final code for the PBO(..O01) and FORM(..F01) includes
Create Container and Object
Create and register events for user interaction
Create ALVtree Hierarchy
Add already exists check!
Create Includes for ALVtree report
Full ABAP code listing of main program
Create Container and Object
Create screen control
Example Output from ALV simple tree display
Create screen control
Create Screen along with PBO and PAI modules
Create Pf-status(screen menu functionality)