REPORT z18_014 .
DATA : con1_ref TYPE REF TO cl_gui_custom_container.
DATA : grid1 TYPE REF TO cl_gui_alv_grid,
gs_variant LIKE disvariant,
gs_cs_variant LIKE disvariant,
gs_layout TYPE lvc_s_layo,
gs_toolbar TYPE ui_functions,
gt_sort TYPE lvc_t_sort,
gt_sflight TYPE TABLE OF sflight.
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_sflight TYPE sflight,
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 sflight.
* Read dragged row
READ TABLE gt_sflight 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_sflight INTO dataobj->wa_sflight 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_sflight INTO gt_sflight INDEX e_row-index.
ELSE.
DELETE gt_sflight INDEX dataobj->index.
INSERT dataobj->wa_sflight INTO gt_sflight INDEX e_row-index.
ENDIF.
CALL METHOD grid1->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 sflight INTO TABLE gt_sflight.
l_scroll-row = 'X'.
l_scroll-col = 'X'.
CALL METHOD grid1->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 sflight.
* Read dragged row
READ TABLE gt_sflight 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_sflight INTO dataobj->wa_sflight 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_sflight INTO gt_sflight INDEX e_row-index.
ELSE.
DELETE gt_sflight INDEX dataobj->index.
INSERT dataobj->wa_sflight INTO gt_sflight INDEX e_row-index.
ENDIF.
CALL METHOD grid1->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 sflight INTO TABLE gt_sflight.
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 grid1
EXPORTING
i_parent = con1_ref.
PERFORM setting_layout.
PERFORM setting_toolbar.
PERFORM setting_sort.
PERFORM setting_event.
PERFORM ASSIGN_HANDLE.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
i_save = 'A'
is_variant = gs_variant " variant display
i_default = ' '
is_layout = gs_layout
it_toolbar_excluding = gs_toolbar
CHANGING
it_outtab = gt_sflight
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 gs_toolbar.
l_exclude = cl_gui_alv_grid=>mc_fc_maintain_variant.
APPEND l_exclude TO gs_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 grid1.
SET HANDLER event_receiver->handle_toolbar FOR grid1.
SET HANDLER event_receiver->handle_command FOR grid1.
CREATE OBJECT g_application.
SET HANDLER g_application->handle_alv_drag FOR grid1.
SET HANDLER g_application->handle_alv_drop FOR grid1.
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
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
91 | REPORT z19_003 | sapjoy | 2007.03.27 | 2476 |
90 | REPORT z19_002 | sapjoy | 2007.03.24 | 2410 |
89 | REPORT z19_001 | sapjoy | 2007.03.23 | 2554 |
88 | REPORT z18_022 | sapjoy | 2007.03.17 | 2477 |
87 | REPORT z18_019 | sapjoy | 2007.03.13 | 2475 |
86 | REPORT z18_018 [4] | sapjoy | 2007.03.12 | 2467 |
» | REPORT z18_014 | sapjoy | 2007.03.10 | 2849 |
84 | REPORT z18_013 [1] | sapjoy | 2007.03.09 | 2588 |
83 | REPORT z18_012 [1] | sapjoy | 2007.03.09 | 2406 |
82 | REPORT Z15_045 | sapjoy | 2007.03.09 | 2394 |
81 | REPORT z18_011 [1] | sapjoy | 2007.03.08 | 2331 |
80 | REPORT z18_008 | sapjoy | 2007.03.07 | 2362 |
79 | REPORT z18_007 | sapjoy | 2007.03.07 | 2207 |
78 | REPORT z18_006 | sapjoy | 2007.03.06 | 2424 |
77 | REPORT z18_005 | sapjoy | 2007.03.06 | 2160 |
76 | REPORT z18_004 [1] | sapjoy | 2007.03.06 | 2349 |
75 | REPORT Z18_002 | sapjoy | 2007.03.06 | 3087 |
74 | Z18_001_PBO | sapjoy | 2007.03.03 | 2590 |
73 | REPORT Z18_001 | sapjoy | 2007.03.03 | 2775 |
72 | REPORT Z02_016 | sapjoy | 2007.02.27 | 2295 |