Skip to Content

Changing a node's site in the ALV tree

Hello experts,

i have an ALV tree and basically what i need to do is to slide (DRAG) a specific node to the top or bottom or a specific site in the ALV tree !

for example, here i wanna slide 'IF' node in place before 'AFFECATIONS' node :

=> Expected node's arrangement :

Any thoughts of how this is could be done ?

capture.jpg (48.5 kB)
prob.jpg (41.0 kB)
res.jpg (38.0 kB)
res.jpg (38.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Jun 29, 2017 at 06:34 PM

    There are the events ON_DRAG* and ON_DROP* so it should be possible. Did you use CL_GUI_ALV_TREE or CL_GUI_ALV_TREE_SIMPLE ?

    Add comment
    10|10000 characters needed characters exceeded

    • You have these 2 demo programs:

      • BCALV_TREE_DND : Drag & Drop within a hierarchy tree
      • BCALV_TREE_DND_MULTIPLE : Drag & Drop within a hierarchy tree

      They show how to use the events mentioned above.

      Here are the most important lines of code for drag & drop handling for CL_GUI_ALV_TREE, which is for single node selection only:

      CLASS lcl_dndobj definiTION.
        public section.
        methods constructor.
      endclass."
      CLASS lcl_dndobj IMPLEMENTATION.
        method constructor.
          "...
        endmethod."
      endclass."
      
      CLASS lcl_app DEFINITION.
        PUBLIC SECTION.
          METHODS on_drag
                FOR EVENT on_drag
                OF cl_gui_alv_tree
                IMPORTING
                  DRAG_DROP_OBJECT
                  FIELDNAME
                  NODE_KEY
                  sender.
          METHODS on_drop
                FOR EVENT on_drop
                OF cl_gui_alv_tree
                IMPORTING
                  DRAG_DROP_OBJECT
                  NODE_KEY
                  sender.
      ENDCLASS."
      
      CLASS lcl_app IMPLEMENTATION.
        METHOD on_drag.
          " DRAG_DROP_OBJECT
          " FIELDNAME
          " NODE_KEY
          data: ls_output type ty_gs_alv_tree.
          CALL METHOD sender->get_outtab_line
            EXPORTING
              i_node_key     = node_key
            IMPORTING
              e_outtab_line  = ls_output
            EXCEPTIONS
              node_not_found = 1
              OTHERS         = 2.
          IF sy-subrc = 0.
            create object DRAG_DROP_OBJECT->object TYPE lcl_dndobj
                exporting 
                  entity_id = ls_output-entity_id.
          ENDIF.
        ENDMETHOD."
       METHOD on_drop.
          " DRAG_DROP_OBJECT
          " NODE_KEY
         data: lo_dndobj TYPE REF TO lcl_dndobj.
         lo_dndobj ?= DRAG_DROP_OBJECT.
       ENDMETHOD."
      ENDCLASS."
      
      SET HANDLER go_app->on_drag FOR go_tree.
      SET HANDLER go_app->on_drop FOR go_tree2.

      You may also find more information at SAP Library: Drag and Drop.