作者:sap侠之大者


ALV Grid的示例程序如下,此程序可以通过拖拽来改变ALV控件数据行的顺序:


1、创建一个600屏幕,只需一个屏幕元素OK_CODE即可

2、创建一个gui status,命名为STATUS,增加对退出按钮的相应

*&---------------------------------------------------------------------* 
*& Report YZ_TEST32
*&
*&---------------------------------------------------------------------*
*© from SAPTechnical.com
*&ALV report with drag and drop functionality on its rows
*&---------------------------------------------------------------------*

REPORT YZ_TEST32 .

*Structure declaration for T016T
TYPES : BEGIN OF TY_T016T ,
BRSCH TYPE BRSCH ,
BRTXT TYPE TEXT1_016T ,
SPRAS TYPE SPRAS ,
END OF TY_T016T .
*Work area 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 .
*class declaration
CLASS LCL_OBJDRAGDROPAPP DEFINITION DEFERRED .
*data declarations 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
*declarations for handle event
DATA : EFFECT TYPE I ,
HANDLE_ALV TYPE I .
*initialization event
INITIALIZATION .
*start of selection event
START-OF-SELECTION .
*select data
PERFORM FETCH_DATA .
*ALV output
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
*Application class definition
CLASS LCL_OBJDRAGDROPAPP DEFINITION .
PUBLIC SECTION .
METHODS :
*Handling Event Drag
HANDLE_ALV_DRAG
FOR EVENT ONDRAG
OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN E_DRAGDROPOBJ ,
*Handling event DROP
HANDLE_ALV_DROP
FOR EVENT ONDROP
OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN E_DRAGDROPOBJ .
ENDCLASS . "LCL_objdragdropapp DEFINITION
*Application class 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