原文地址:实现ALV Grid 和ALV Tree的拖拽功能 作者:sap侠之大者
使用class CL_GUI_ALV_TREE
和CL_GUI_ALV_GRID的ON_DRAG、ON_DROP 事件来实现相应的拖拽功能。
ALV Grid的示例程序如下,此程序可以通过拖拽来改变ALV控件数据行的顺序:
1、创建一个600屏幕,只需一个屏幕元素OK_CODE即可
2、创建一个gui status,命名为STATUS,增加对退出按钮的相应
*&---------------------------------------------------------------------*
*&Report YZ_TEST32
*&
*&---------------------------------------------------------------------*
*©from SAPTechnical.com
*&ALVreport with drag and drop functionality on its rows
*&---------------------------------------------------------------------*
REPORT YZ_TEST32.
*Structuredeclaration for T016T
TYPES : BEGIN OF TY_T016T,
BRSCH TYPE BRSCH,
BRTXT TYPE TEXT1_016T,
SPRAS TYPE SPRAS,
END OF TY_T016T.
*Workarea and internal table for T016T
DATA : IT_T016T TYPE STANDARD TABLE OF TY_T016T,
WA_T016T TYPE TY_T016T.
DATA OK_CODE LIKE SY-UCOMM.
*classdeclaration
CLASS LCL_OBJDRAGDROPAPP DEFINITION DEFERRED.
*datadeclarations for alv
DATA: C_DRAGDROPAPP TYPE REF TO LCL_OBJDRAGDROPAPP,
C_DOCKINGCONT TYPE REF TO CL_GUI_DOCKING_CONTAINER,
C_ALV TYPE REF TO CL_GUI_ALV_GRID,
*reference variable to CL_DRAGDROP:
C_DRAGDROPALV TYPE REF TO CL_DRAGDROP,
IT_LAYOUT TYPE LVC_S_LAYO,
IT_FCAT TYPE LVC_T_FCAT. "Field catalogue
*declarationsfor handle event
DATA: EFFECT TYPE I,
HANDLE_ALV TYPE I.
*initializationevent
INITIALIZATION.
*startof selection event
START-OF-SELECTION.
*selectdata
PERFORM FETCH_DATA.
*ALVoutput
PERFORM ALV_OUTPUT.
*Class definitions and method implementation for drag and drop
CLASS LCL_DRAGDROP DEFINITION.
PUBLIC SECTION.
DATA: WA TYPE TY_T016T,
INDEX TYPE I. "Index of Line to be moved
ENDCLASS. "LCL_DRAGDROP DEFINITION
*Applicationclass definition
CLASS LCL_OBJDRAGDROPAPP DEFINITION.
PUBLIC SECTION.
METHODS:
*HandlingEvent Drag
HANDLE_ALV_DRAG
FOR EVENT ONDRAG
OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN E_DRAGDROPOBJ,
*Handlingevent DROP
HANDLE_ALV_DROP
FOR EVENT ONDROP
OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN E_DRAGDROPOBJ.
ENDCLASS. "LCL_objdragdropapp DEFINITION
*Applicationclass implementation
CLASS LCL_OBJDRAGDROPAPP IMPLEMENTATION.
* OnDrag event is used to 'fetch' information from the drag source.
METHOD HANDLE_ALV_DRAG.
DATA: DATAOBJ TYPE REF TO LCL_DRAGDROP,
LINE TYPE TY_T016T.
*Read dragged row
READ TABLE IT_T016T INDEX E_ROW-INDEX INTO LINE.
*create and fill dataobject for events ONDROP
CREATE OBJECT DATAOBJ.
*Remembering row index to move a line
MOVE E_ROW-INDEX TO DATAOBJ->INDEX.
*store the dragged line.
READ TABLE IT_T016T INTO DATAOBJ->WA INDEX E_ROW-INDEX.
*Assigning data object to
*&
*&
*&---------------------------------------------------------------------*
*©
*&ALV
*&---------------------------------------------------------------------*
REPORT
*Structure
TYPES
*Work
DATA
DATA
*class
CLASS
*data
DATA:
*
*declarations
DATA:
*initialization
INITIALIZATION.
*start
START-OF-SELECTION.
*select
*ALV
*
CLASS
ENDCLASS.
*Application
CLASS
*Handling
*Handling
ENDCLASS.
*Application
CLASS
*
*
*
*
*
*