REPORT Z15_14.
DATA : con1_ref TYPE REF TO cl_gui_custom_container.
DATA : g_grid TYPE REF TO cl_gui_alv_grid.
DATA : gt_emplist TYPE TABLE OF zemplist.
DATA : gs_variant TYPE disvariant.
DATA : gs_layout TYPE lvc_s_layo.
DATA : gt_toolbar TYPE ui_functions.
DATA : gt_sort TYPE lvc_t_sort.
DATA : ok_code TYPE sy-ucomm.
TYPE-POOLS: icon.
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS: handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column.
METHODS : handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
METHODS : handle_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
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.
PRIVATE SECTION.
ENDCLASS. "lcl_event_receiver DEFINITION
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).
*#####################################################################
* 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_emplist TYPE zemplist,
index TYPE i. "Index of Line to be moved or copied.
ENDCLASS. "LCL_DRAGDROPOBJ DEFINITION
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. "LCL_APPLICATION DEFINITION
*---------------------------------------------------------------------*
* 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 zemplist.
* Read dragged row
READ TABLE gt_emplist 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_emplist INTO dataobj->wa_emplist 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. "HANDLE_ALV_DRAG
*--------------------------------------------------------------------
* §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_emplist INTO gt_emplist INDEX e_row-index.
ELSE.
DELETE gt_emplist INDEX dataobj->index.
INSERT dataobj->wa_emplist INTO gt_emplist INDEX e_row-index.
ENDIF.
CALL METHOD g_grid->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. "HANDLE_ALV_DROP
ENDCLASS. "LCL_APPLICATION IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_double_click.
LEAVE TO SCREEN 0.
ENDMETHOD. "handle_double_click
*-- Add ToolBar
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
CLEAR ls_toolbar.
ls_toolbar-butn_type = 3.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
ls_toolbar-function = 'RESH'.
ls_toolbar-icon = icon_refresh.
ls_toolbar-quickinfo = 'Refresh'.
ls_toolbar-text = ' '.
ls_toolbar-disabled = ' '.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
METHOD handle_command.
DATA : l_scroll TYPE lvc_s_stbl.
CASE e_ucomm.
*- REFRESH
WHEN 'RESH'.
SELECT * FROM zemplist INTO TABLE gt_emplist.
l_scroll-row = 'X'.
l_scroll-col = 'X'.
CALL METHOD g_grid->refresh_table_display
EXPORTING
i_soft_refresh = ''
is_stable = l_scroll.
ENDCASE.
ENDMETHOD. "handle_user_command
METHOD handle_alv_drag.
DATA: dataobj TYPE REF TO lcl_dragdropobj,
line TYPE zemplist.
* Read dragged row
READ TABLE gt_emplist 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_emplist INTO dataobj->wa_emplist 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. "HANDLE_ALV_DRAG
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_emplist INTO gt_emplist INDEX e_row-index.
ELSE.
DELETE gt_emplist INDEX dataobj->index.
INSERT dataobj->wa_emplist INTO gt_emplist INDEX e_row-index.
ENDIF.
CALL METHOD g_grid->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. "HANDLE_ALV_DROP
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
*
DATA : event_receiver TYPE REF TO lcl_event_receiver.
START-OF-SELECTION.
SELECT * FROM zemplist INTO TABLE gt_emplist.
CALL SCREEN 100.
*---------------------------------------------------------------------*
* MODULE init_con OUTPUT
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
MODULE init_con OUTPUT.
IF con1_ref IS INITIAL.
CREATE OBJECT con1_ref
EXPORTING container_name = 'CON1'.
CREATE OBJECT g_grid
EXPORTING
i_parent = con1_ref.
PERFORM setting_layout.
PERFORM setting_toolbar.
PERFORM setting_sort.
PERFORM setting_event.
PERFORM ASSIGN_HANDLE.
CALL METHOD g_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'emplist'
i_save = 'A'
is_variant = gs_variant " variant display
i_default = ' '
is_layout = gs_layout
it_toolbar_excluding = gt_toolbar
CHANGING
it_outtab = gt_emplist
it_sort = gt_sort.
ENDIF.
ENDMODULE. " init_con OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'G100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK' OR 'EXIT' OR 'CANC'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form setting_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_LAYOCAT text
*----------------------------------------------------------------------*
FORM setting_layout .
*- General display options
gs_layout-cwidth_opt = 'X'.
* TITLE BAR
gs_layout-grid_title = 'Drag & Drop TEST'.
* Selection modes for SEL_MODE
* gs_layout-sel_mode = 'D'.
* Grid pattern
gs_layout-zebra = 'X'.
ENDFORM. " setting_layout
*&---------------------------------------------------------------------*
*& Form setting_toolbar
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_TOOLBAR text
*----------------------------------------------------------------------*
FORM setting_toolbar.
DATA: l_exclude TYPE ui_func.
l_exclude = cl_gui_alv_grid=>mc_fc_save_variant.
APPEND l_exclude TO gt_toolbar.
l_exclude = cl_gui_alv_grid=>mc_fc_maintain_variant.
APPEND l_exclude TO gt_toolbar.
ENDFORM. " setting_toolbar
*&---------------------------------------------------------------------*
*& Form setting_sort
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM setting_sort .
DATA : ls_sort TYPE lvc_s_sort.
ls_sort-spos = '1'.
ls_sort-fieldname = 'CARRID'.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO gt_sort.
ENDFORM. " setting_sort
*&---------------------------------------------------------------------*
*& Form setting_event
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM setting_event .
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_double_click FOR g_grid.
SET HANDLER event_receiver->handle_toolbar FOR g_grid.
SET HANDLER event_receiver->handle_command FOR g_grid.
CREATE OBJECT g_application.
SET HANDLER g_application->handle_alv_drag FOR g_grid.
SET HANDLER g_application->handle_alv_drop FOR g_grid.
ENDFORM. " setting_event
*&---------------------------------------------------------------------*
*& Form ASSIGN_HANDLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form 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. " ASSIGN_HANDLE
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
443 | REPORT Z15_22 | 가능 | 2025.09.22 | 0 |
442 | REPORT Z15_21 | 가능 | 2025.09.22 | 0 |
441 | REPORT Z15_20 | 가능 | 2025.09.22 | 0 |
440 | REPORT Z15_19 | 가능 | 2025.09.22 | 0 |
439 | REPORT Z15_18 | 가능 | 2025.09.22 | 0 |
438 | REPORT Z15_17 | 가능 | 2025.09.22 | 0 |
437 | REPORT Z15_16 | 가능 | 2025.09.22 | 1 |
436 | REPORT Z15_15 | 가능 | 2025.09.22 | 0 |
» | REPORT Z15_14 | 가능 | 2025.09.22 | 0 |
434 | REPORT Z15_13 | 가능 | 2025.09.22 | 0 |
433 | REPORT Z15_12 | 가능 | 2025.09.22 | 1 |
432 | REPORT Z15_11 | 가능 | 2025.09.22 | 0 |
431 | REPORT Z15_10 | 가능 | 2025.09.22 | 0 |
430 | REPORT Z15_09 | 가능 | 2025.09.22 | 1 |
429 | INCLUDE Z15_08F01 | 가능 | 2025.09.22 | 1 |
428 | INCLUDE Z15_08O01 | 가능 | 2025.09.22 | 0 |
427 | INCLUDE Z15_08TOP | 가능 | 2025.09.22 | 0 |
426 | REPORT Z15_08 | 가능 | 2025.09.22 | 2 |
425 | INCLUDE Z15_07F01 | 가능 | 2025.09.22 | 0 |
424 | INCLUDE Z15_07O01 | 가능 | 2025.09.22 | 1 |