ALV Grid控制元件拖放功能
系統自帶程式BCALV_DND_04。
[@more@]REPORT ZALVGRID_DRAGDROP MESSAGE-ID TREE_CONTROL_MSG.
*-------------------------------------------------------------------
* Purpose
* ~~~~~~~
* This example shows how to define a drag and drop behaviour using
* a drag and drop control.
* The behaviour is defined within one ALV Control.
*--------------------------------------------------------------------
* To check program behaviour:
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Try to move or copy lines by dragging them to another position of
* the grid control.
*---------------------------------------------------------------------
* Essential steps: (Search for '§')
* ~~~~~~~~~~~~~~~~
* 1. Define reference variables to CL_DRAGDROP: In this case
* you need only one for a D&D-behaviour within one ALV Control.
* 2. Define a behaviour for drag and drop on alv objects
* and get its handle.
* 3. Link defined behaviour to all rows of the ALV Control.
* 4. Define a class for a data object to exchange data
* within ALV Control when using the drag and drop operation.
* 5. Define methods for two events raised by the drag and drop
* control. (Note that the names for these events depend on
* the classes for which the behaviour was defined!).
* 6. In the 'onDrag' event handler create a data object and fill it with
* appropriate data for your intended operation. This event is used
* to 'fetch' information from the drag source.
* 7. Assign your data object to the refering event parameter.
* This parameter ensures that your data object can be referenced
* in each of the following events.
* 8. Implement the event handler for event 'OnDrop'. This event is used
* to use your dragged information in combination with your drop
* source. What is more, you should make all checks
* if the operation is successful _at this point_.
* 9. Check which operation the user has conducted (copy or move).
*----------------------------------------------------------------------START-OF-SELECTION.
SET SCREEN 100.
*#####################################################################
* global data
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CLASS LCL_APPLICATION DEFINITION DEFERRED.
DATA:
G_APPLICATION TYPE REF TO LCL_APPLICATION,
G_DOCKING_CONTAINER TYPE REF TO CL_GUI_DOCKING_CONTAINER,
G_ALV TYPE REF TO CL_GUI_ALV_GRID,
* §1. Define reference variables to CL_DRAGDROP: In this case
* you need only one for a D&D-behaviour within one ALV Control.
G_BEHAVIOUR_ALV TYPE REF TO CL_DRAGDROP,
* G_OK_CODE TYPE SY-UCOMM,
GT_OUTTAB TYPE TABLE OF SBOOK,
g_max type i value 50.
* You need the layout structure of alv to transfer the handle
* of your defined behaviour (see step 2). DATA: GS_LAYOUT TYPE LVC_S_LAYO.
*#####################################################################
* Class definitions and method implementation
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* §4. Define a class for a data object to exchange data
* within ALV Control when using the drag and drop operation.CLASS LCL_DRAGDROPOBJ DEFINITION.
PUBLIC SECTION.
DATA: WA_SBOOK TYPE SBOOK,
INDEX TYPE I. "Index of Line to be moved or copied.
ENDCLASS.
*---------------------------------------------------------------------*
* CLASS LCL_APPLICATION DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* §5. Define methods for two events raised by the drag and drop
* control. (Note that the names for these events depend on
* the classes for which the behaviour was defined!).CLASS LCL_APPLICATION DEFINITION.
PUBLIC SECTION.
METHODS:
HANDLE_ALV_DRAG
FOR EVENT ONDRAG
OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN E_DRAGDROPOBJ,
HANDLE_ALV_DROP
FOR EVENT ONDROP
OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN E_DRAGDROPOBJ.
ENDCLASS.
*---------------------------------------------------------------------*
* CLASS LCL_APPLICATION IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
CLASS LCL_APPLICATION IMPLEMENTATION.
*-------------------------------------------------------------------
* §6.In the 'onDrag' event handler create a data object and fill it with
* appropriate data for your intended operation. This event is used
* to 'fetch' information from the drag source. METHOD HANDLE_ALV_DRAG.
DATA: DATAOBJ TYPE REF TO LCL_DRAGDROPOBJ,
LINE TYPE SBOOK.
* Read dragged row READ TABLE GT_OUTTAB INDEX E_ROW-INDEX INTO LINE.
* create and fill dataobject for events ONDROP and ONDROPCOMPLETE CREATE OBJECT DATAOBJ.
* remember the row index to copy or move a line MOVE E_ROW-INDEX TO DATAOBJ->INDEX.
* store the dragged line, too.
READ TABLE GT_OUTTAB INTO DATAOBJ->WA_SBOOK INDEX E_ROW-INDEX.
* §7. Assign your data object to the refering event parameter.
* This parameter ensures that your data object can be referenced
* in each of the following events.
E_DRAGDROPOBJ->OBJECT = DATAOBJ.
ENDMETHOD.
*--------------------------------------------------------------------
* §8.Implement the event handler for event 'OnDrop'. This event is used
* to use your dragged information in combination with your drop
* source. What is more, you should make all checks
* if the operation is successful _at this point_. METHOD HANDLE_ALV_DROP.
DATA: DATAOBJ TYPE REF TO LCL_DRAGDROPOBJ,
DROP_INDEX TYPE I,
LS_SBOOK TYPE SBOOK,
STABLE TYPE LVC_S_STBL.
* Refresh Alv Grid Control without scrolling STABLE-ROW = 'X'.
STABLE-COL = 'X'.
*!!!
* Very importent: 'e_dragDropObj->object' can have any instance type
* The needed cast type may lead to a system-exception if the
* cast can not be performed.
* For this reason: use ALWAYS the Catch-Statement to make sure
* that the drag&drop-Operation is aborted properly.
*!!! CATCH SYSTEM-EXCEPTIONS MOVE_CAST_ERROR = 1.
DATAOBJ ?= E_DRAGDROPOBJ->OBJECT.
* 9. Check which operation the user has conducted (copy or move).
IF E_DRAGDROPOBJ->EFFECT EQ CL_DRAGDROP=>COPY.
INSERT DATAOBJ->WA_SBOOK INTO GT_OUTTAB INDEX E_ROW-INDEX.
ELSE.
DELETE GT_OUTTAB INDEX DATAOBJ->INDEX.
INSERT DATAOBJ->WA_SBOOK INTO GT_OUTTAB INDEX E_ROW-INDEX.
ENDIF.
CALL METHOD G_ALV->REFRESH_TABLE_DISPLAY
EXPORTING I_SOFT_REFRESH = 'X'
IS_STABLE = STABLE.
ENDCATCH.
IF SY-SUBRC <> 0.
* If anything went wrong this is the clean way of aborting the
* drag and drop operation: CALL METHOD E_DRAGDROPOBJ->ABORT.
ENDIF.
ENDMETHOD.
ENDCLASS.
*#####################################################################
*&---------------------------------------------------------------------*
*& Module PBO_0400 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*MODULE PBO_100 OUTPUT.
SET PF-STATUS 'MAIN'.
set titlebar 'MAIN'.
IF G_ALV IS INITIAL.
PERFORM CREATE_AND_INIT_CONTROLS.
ENDIF.
ENDMODULE. " PBO_0100 OUTPUT
*#####################################################################
*&---------------------------------------------------------------------*
*& Module PAI_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*MODULE PAI_100 INPUT.
CASE G_OK_CODE.
WHEN 'BACK'. " Finish program
IF NOT G_DOCKING_CONTAINER IS INITIAL.
CALL METHOD G_DOCKING_CONTAINER->FREE
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
IF SY-SUBRC <> 0.
MESSAGE A000.
ENDIF.
CALL METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
IF SY-SUBRC <> 0.
MESSAGE A000.
ENDIF.
CLEAR G_DOCKING_CONTAINER.
CLEAR G_ALV.
ENDIF.
LEAVE PROGRAM.
ENDCASE.
* CAUTION: clear ok code! CLEAR G_OK_CODE.
ENDMODULE. " PAI_0100 INPUT
*#####################################################################
* Forms
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*&---------------------------------------------------------------------*
*& Form CREATE_AND_INIT_CONTROLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*FORM CREATE_AND_INIT_CONTROLS.
* create docking container for alv control CREATE OBJECT G_DOCKING_CONTAINER
EXPORTING
DYNNR = '100'
EXTENSION = 260
SIDE = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_TOP.
* create alv control CREATE OBJECT G_ALV
EXPORTING I_PARENT = G_DOCKING_CONTAINER.
* create the application object
* this object is needed to handle the ABAP Objects Events of
* Controls CREATE OBJECT G_APPLICATION.
* Events alv control SET HANDLER G_APPLICATION->HANDLE_ALV_DRAG FOR G_ALV.
SET HANDLER G_APPLICATION->HANDLE_ALV_DROP FOR G_ALV.
* build tree nodes and describe behaviour of drag&drop PERFORM BUILD_AND_ASSIGN_HANDLE.
* select and display data from SBOOK SELECT * FROM SBOOK INTO TABLE GT_OUTTAB up to g_max rows. "#EC CI_NOWHERE
GS_LAYOUT-GRID_TITLE = TEXT-101.
CALL METHOD G_ALV->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING I_STRUCTURE_NAME = 'SBOOK'
IS_LAYOUT = GS_LAYOUT
CHANGING IT_OUTTAB = GT_OUTTAB.
ENDFORM. " CREATE_AND_INIT_CONTROLS
*&---------------------------------------------------------------------*
*& Form build_nodes_and_handles
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM BUILD_AND_ASSIGN_HANDLE.
DATA: EFFECT TYPE I,
HANDLE_ALV TYPE I.
* §2. Define a behaviour for drag and drop on alv objects
* and get its handle.
* define a drag & Drop behaviour for the whole grid CREATE OBJECT G_BEHAVIOUR_ALV.
EFFECT = CL_DRAGDROP=>MOVE + CL_DRAGDROP=>COPY.
CALL METHOD G_BEHAVIOUR_ALV->ADD
EXPORTING
FLAVOR = 'Line' "#EC NOTEXT
DRAGSRC = 'X'
DROPTARGET = 'X'
EFFECT = EFFECT.
CALL METHOD G_BEHAVIOUR_ALV->GET_HANDLE
IMPORTING HANDLE = HANDLE_ALV.
*..........
* §3. Link defined behaviour to all rows of the ALV Control.
*
* Remark: The place at which you transfer your handle is control
* dependend!
* provide handle to alv control using the layout-structure
* In this example all rows obtain the same drag and drop behaviour: GS_LAYOUT-S_DRAGDROP-ROW_DDID = HANDLE_ALV.
ENDFORM. " build_nodes_and_handles
*#####################################################################
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8214011/viewspace-910676/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ALV類應用-GRID
- SAP: 建立ALV GRID容器
- SAP: ALV GRID行顏色
- ALV_GRID_DISPLAY中設定SORT
- function方式的ALV中 增加按鈕 用 REUSE_ALV_GRID_DISPLAYFunction
- Html5的拖放功能HTML
- ABAP FM: REUSE_ALV_GRID_LAYOUT_INFO_GET
- 指令碼div實現拖放功能指令碼
- 使用VB實現OLE拖放功能
- SAP: ALV GRID 控制之 單元格按鈕
- vue專案中加入拖放排序功能Vue排序
- ABAP--處理'REUSE_ALV_GRID_DISPLAY'的雙擊事件事件
- 在alv grid中的列中設定icon圖示
- (轉)關於REUSE_ALV_GRID_DISPLAY函式的slis_layout_alv的欄位使用的說明函式
- (轉)ABAP--處理'REUSE_ALV_GRID_DISPLAY'的雙擊事件事件
- SAP: ALV GRID 追加核取方塊欄位及編輯時立刻呼叫事件事件
- HTML 5 拖放HTML
- function ALV 獲取OO ALV event IDFunction
- 使用vue實現grid-layout功能Vue
- HTML5 進階系列:拖放 API 實現拖放排序HTMLAPI排序
- HTML5 拖放HTML
- HTML5拖放HTML
- SAP UI5 sap.ui.layout.Grid 控制元件概述UI控制元件
- ALV_FieldEdit
- chrome下的拖放事件Chrome事件
- H5 元素拖放H5
- tlistview使用--拖放操作 (轉)View
- 控制元件測試功能點3控制元件
- ALV1:使用函式顯示ALV格式報表函式
- ALV示例---Dyoprn實現,一個容器中嵌入ALV報表
- HTML5 拖放、交換位置HTML
- javascript的拖放入門(轉)JavaScript
- Flutter 分頁功能表格控制元件Flutter控制元件
- 控制元件測試功能點摘要2控制元件
- 自己寫的ALV程式
- ALV LAYOUT的設定
- 〔轉載〕ALV知識
- 手機端上傳照片實現 壓縮、拖放、縮放、裁剪、合成拼圖等功能