Copyright 2024 - BV TallVision IT

Drag & drop can be implemented with ALV or hierarchies as well, here's how... (Abap Objects). There are events for dragging & dropping whatever you would like to drag around. The main ingredients for Drag & drop:

Dragdrop events class definition

In case you are working with an ALV, class cl_gui_alv_grid- the events which are related to the drag & drop actions need to be responded to. This is done by implementing a class in which the respective events are handled, like this:


class cl_dragdrop_events definition.
  public section.
      my_alv_drag for event ondrag of cl_gui_alv_grid
        importing e_row  e_column  e_dragdropobj,
      my_alv_drop_complete for event ondropcomplete
        of cl_gui_alv_grid
        importing e_row e_column e_dragdropobj.

The following events can be responded to when the drag & drop operations are set up from class:

  • cl_gui_alv_grid: ondrag, ondrop, ondropcomplete,ondropgetflavor
  • cl_gui_alv_tree: on_drag, on_drag_multiple, on_drop, on_drop_multiple, on_drop_complete, on_drop_complete_multiple, on_drop_get_flavor.

(See transaction SE24 events).

Dragdrop events class implementation

The actual methods will have to be defined now. The parameter e_dragdropobj can be used to respond to the drag & drop move: e.g. by doing an abort: e_dragdropobj->abort. As a drag & drop operation can change the source as well as the target, make sure both source and targets are refreshed when the move completes. For an ALV grid this can e.g. be done by method refresh_table_display (class cl_gui_alv_grid) or for a tree hierarchy the frontend_update (class cl_gui_alv_tree) should do the trick.

One other thing needs to be looked after: the information that gets dragged around is to be set up as your own data object. Create a class and put in some public section. with your data (the data needed to identify the move. This object will act as the communication object for the drag & drop action. Simply set e_dragdropobj->object in the event that handles ondrag. The same information can then be picked up again when handling the ondrop event.

Set the event handler

When the response of a drag and drop is catered for (previous paragraphs) an event handler needs to be set. An event handler is in effect the implementation of the drag_drop class that we have defined before. Once the class is implemented, it needs to be made aware which object it needs to process event handlers for. Thus: we have an ALV list object with contents (1), we also have an implemented class which looks after drag & drop responses (2) and now we need to make sure this class is will "handle" the events for the ALV list object alv_obj:

data: my_dragdrop_event_handler 
        type ref to cl_dragdrop_events.

  create object my_dragdrop_event_handler.

  set handler: dd_event_handler->alv_drag for alv_obj,
      dd_event_handler->alv_drop_complete for alv_obj.