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: 

Changing a node's site in the ALV tree

0 Kudos

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 ?

5 REPLIES 5

0 Kudos

Please any help ?? i haven't found any soultion yet 😞

Sandra_Rossi
Active Contributor
0 Kudos

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 ?

0 Kudos

Heloo Sandra,

i used CL_GUI_ALV_TREE , what i m looking for just hoa to change the arrangement's nodes !!?

best regards.

Hamza CHIOUA.

0 Kudos

Please any help ? i still haven't any solution for this task 😕

0 Kudos

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.