ALVtree toolbar processing

Define class to handle user defined ALVtree toolbar buttons. Insert at end of DATA declaration section but before any ABAP processing.


*--------------------------------------------------------------*
*   INCLUDE ZTEST_TOOLBAR_EVENT_RECEIVER                       *
*--------------------------------------------------------------*
data mr_toolbar type ref to cl_gui_toolbar.  "Add to top include
CLASS lcl_toolbar_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS: on_function_selected
               FOR EVENT function_selected OF cl_gui_toolbar
                 IMPORTING fcode,
             on_toolbar_dropdown
               FOR EVENT dropdown_clicked OF cl_gui_toolbar
                 IMPORTING fcode
                           posx
                           posy.
ENDCLASS.
*-------------------------------------------------------------*
*       CLASS lcl_toolbar_event_receiver IMPLEMENTATION
*-------------------------------------------------------------*
*       ........                                              *
*-------------------------------------------------------------*
CLASS lcl_toolbar_event_receiver IMPLEMENTATION.
  METHOD on_function_selected.
    DATA: ls_sflight TYPE sflight.
    DATA: lt_list_commentary TYPE slis_t_listheader,
          l_logo             TYPE sdydo_value.
*   Processing for user defined tollbar button goes here
    CASE fcode.
      WHEN 'NEXT'.
      WHEN 'DELETE'.
        DATA: lt_selected_node TYPE lvc_t_nkey.
        DATA: e_selected_node     TYPE lvc_nkey,
              e_fieldname         TYPE lvc_fname.
        DATA: lt_outtab_line(100)  TYPE c,
              lt_node_text         TYPE lvc_value.
        CALL METHOD gd_tree->get_selected_nodes
                CHANGING
                   ct_selected_nodes = lt_selected_node.
      WHEN 'INSERT_LC'.
*     Code for function code INSERT_LC goes here
      WHEN 'INSERT_FC'.
*     Code for function code INSERT_FC goes here
      WHEN 'INSERT_FS'.
*     Code for function code INSERT_FS goes here
      WHEN 'INSERT_LS'.
*     Code for function code INSERT_LS goes here
      WHEN 'INSERT_NS'.
*     Code for function code INSERT_NS goes here
    ENDCASE.
*   update frontend
    CALL METHOD gd_tree->frontend_update.
  ENDMETHOD.
  METHOD on_toolbar_dropdown.
* create contextmenu
    DATA: l_menu TYPE REF TO cl_ctmenu,
          l_fc_handled TYPE as4flag.
    CREATE OBJECT l_menu.
    CLEAR l_fc_handled.
*   Setup Insert button so options are displayed as drop doan menu
    CASE fcode.
      WHEN 'INSERT_LC'.
        l_fc_handled = 'X'.
*       insert as last child
        CALL METHOD l_menu->add_function
                EXPORTING fcode   = 'INSERT_LC'
                text    = 'Insert New Line as Last Child'.  "#EC NOTEXT
*       insert as first child
        CALL METHOD l_menu->add_function
                EXPORTING fcode   = 'INSERT_FC'
                text    = 'Insert New Line as First Child'. "#EC NOTEXT
*       insert as next sibling
        CALL METHOD l_menu->add_function
                EXPORTING fcode   = 'INSERT_NS'
                text    = 'Insert New Line as Next Sibling'."#EC NOTEXT
*       insert as last sibling
        CALL METHOD l_menu->add_function
                EXPORTING fcode   = 'INSERT_LS'
                text    = 'Insert New Line as Last Sibling'."#EC NOTEXT
*       insert as first sibling
        CALL METHOD l_menu->add_function
                EXPORTING fcode   = 'INSERT_FS'
              text    = 'Insert New Line as First Sibling'. "#EC NOTEXT
    ENDCASE.
* show dropdownbox
    IF l_fc_handled = 'X'.
      CALL METHOD mr_toolbar->track_context_menu
        EXPORTING
            context_menu = l_menu
            posx         = posx
            posy         = posy.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

Related Articles

Activate user interaction within SAP ALV tree
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)
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)