原文地址:实现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 .
DATAOK_CODE
LIKE
SY -UCOMM .
*classdeclaration
CLASSLCL_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
CLASSLCL_DRAGDROP
DEFINITION .
PUBLIC
SECTION .
DATA :
WA
TYPE
TY_T016T ,
*&
*&
*&---------------------------------------------------------------------*
*©
*&ALV
*&---------------------------------------------------------------------*
REPORT
*Structure
TYPES
*Work
DATA
DATA
*class
CLASS
*data
DATA :
*
*declarations
DATA :
*initialization
INITIALIZATION .
*start
START-OF-SELECTION .
*select
*ALV
*
CLASS