Start of Content Area

Process documentationProcess Flow of a Drag and Drop Operation  Locate the document in its SAP Library structure


The following section explains how a drag and drop operation works, examining into the roles of the application server and frontend, and going on to identify the individual steps required to program drag and drop in an application.

Process Flow

Application Server

  1. You create the custom control.
  2. You register the drag and drop events.
  3. You define the drag and drop behavior for the individual custom controls or their components. To do this, you create an instance of the class CL_DRAGDROP. You then assign one or more flavors to this instance. These describe the drag and drop behavior of the relevant custom control. During the program, you can change, delete, and query the flavors in your program. You can also initialize or destroy the entire instance.
  4. You assign flavors to the custom control using specific methods of the relevant control. For further information, refer to the corresponding control documentation.
  5. Frontend

    The following steps are performed by the system at the frontend. They are only listed here so that you can understand what happens during a drag and drop operation.

  6. Once the use has selected an object with the left mouse button, the drag and drop service starts.
  7. The drag and drop service checks whether a drag and drop behavior has been defined for the object, and whether the object can be dragged (DragSource attribute).
  8. If, according to the DragSource attribute, the object can be dragged, the drag and drop operation starts. The mouse pointer then changes automatically.
  9. As long as the left mouse button remains pressed, the system continually checks whether the mouse pointer is positioned over an object in a custom control that can receive a dropped object (DropTarget attribute), and whether the flavor of that object is the same as the flavor of the source. If this is the case, the mouse pointer changes again to inform the user.
  10. If the user now drops the object, an event is triggered to inform the application server.
  11. Note

    This concludes the drag and drop operation for the frontend. However, there has not yet been any change to the contents of the custom control.

    Application Server

  12. The drag and drop service of the application server creates an instance of the class CL_DRAGDROPOBJECT. You can use this instance (for example, drag_drop_object ) in all events of the drag and drop process as an event parameter. You can use it to find out the context between the events.
  13. The drag and drop service checks whether the drag object and drop object have more than one flavor in common. If this is the case, the event ONGETFLAVOR is triggered. In the corresponding handler method, you must decide which flavor to use. You do this using the method set_flavor.
  14. Now, the drag and drop event ONDRAG is triggered. It has event parameters that tell you which object the user has dragged. Within the handler routine, you must pass the context (information about the source object) to the instance of the drag and drop data object created in step 9.
    drag_drop_object->object = mydragobject.
  15. Next, the ONDROP event is triggered. The corresponding handler method serves to process the drag and drop data object. Here, you have to implement the changes that are to be made to the target object based on the drag and drop operation.
  16. The last event of the drag and drop operation is ONDROPCOMPLETE . This is where you can make your last changes to the drag and drop object. In particular, you should use this event to delete the source object from the DragSource control and the corresponding data structures if you have used the drag and drop operation to move the object.


The Example of Drag and Drop Programming contains an example of a drag and drop operation between a SAP Tree and a SAP Textedit.