REPORT z18_06_dragndrop.
DATA: g_alv_tree TYPE REF TO cl_gui_alv_tree,
g_custom_container TYPE REF TO cl_gui_custom_container.
DATA: gt_sflight TYPE sflight OCCURS 0,
gt_itab TYPE sflight OCCURS 0 WITH HEADER LINE,
ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm,
g_max TYPE i VALUE 255.
DATA : gt_fieldcatalog TYPE lvc_t_fcat.
* BEHAVIOR
DATA: g_fav_behaviour TYPE REF TO cl_dragdrop,
g_line_behaviour TYPE REF TO cl_dragdrop.
DATA : BEGIN OF drg_node OCCURS 0 .
DATA : key TYPE lvc_nkey.
DATA : END OF drg_node.
* drag
DATA : lt_nodes TYPE lvc_t_nkey,
ls_nodes TYPE lvc_nkey,
lt_pat_node1 TYPE lvc_t_nkey,
pat_node1 TYPE lvc_nkey,
pat_node2 TYPE lvc_nkey,
pat_node3 TYPE lvc_nkey,
g_fav_key TYPE lvc_nkey.
* toolbar
DATA mr_toolbar TYPE REF TO cl_gui_toolbar.
INCLUDE z18_06_dragclass.
*include Z18_06_drag.
END-OF-SELECTION.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module PBO OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
IF g_alv_tree IS INITIAL.
PERFORM init_tree.
ENDIF.
ENDMODULE. " PBO OUTPUT
*&---------------------------------------------------------------------*
*& Form INIT_TREE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_tree .
DATA: l_tree_container_name(30).
DATA: lv_layout TYPE disvariant.
lv_layout-report = sy-repid.
l_tree_container_name = 'CCONTAINER1'.
CREATE OBJECT g_custom_container
EXPORTING
container_name = l_tree_container_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'(100).
ENDIF.
CREATE OBJECT g_alv_tree
EXPORTING
parent = g_custom_container
node_selection_mode =
cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'
no_html_header = 'X'
no_toolbar = ''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'.
ENDIF.
DATA: l_hierarchy_header TYPE treev_hhdr.
PERFORM build_hierarchy_header CHANGING l_hierarchy_header.
PERFORM build_fieldcatalog.
CALL METHOD g_alv_tree->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
is_hierarchy_header = l_hierarchy_header
* is_variant = lv_layout
CHANGING
it_fieldcatalog = gt_fieldcatalog
it_outtab = gt_sflight. "table must be empty !
DATA l_style TYPE i.
l_style = cl_gui_column_tree=>style_emphasized. "style_inactive.
CALL METHOD g_alv_tree->set_calculation_style
EXPORTING
i_calculation_style = l_style.
* behavior
PERFORM define_dnd_behaviour.
PERFORM create_hierarchy.
* drag
PERFORM register_events.
* TOOLBAR
PERFORM register_toolbar.
CALL METHOD g_alv_tree->update_calculations.
CALL METHOD g_alv_tree->frontend_update.
ENDFORM. " INIT_TREE
*&---------------------------------------------------------------------*
*& Form BUILD_HIERARCHY_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_L_HIERARCHY_HEADER text
*----------------------------------------------------------------------*
FORM build_hierarchy_header CHANGING p_hierarchy_header TYPE treev_hhdr.
p_hierarchy_header-heading = 'Month/Carrier/Date'(300).
p_hierarchy_header-tooltip = 'Flights in a month'(400).
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = ' '.
ENDFORM. " BUILD_HIERARCHY_HEADER
*&---------------------------------------------------------------------*
*& Form CREATE_HIERARCHY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_hierarchy .
DATA: ls_sflight TYPE sflight,
l_carrid LIKE sflight-carrid,
l_carrid_last LIKE sflight-carrid.
DATA: l_node_key TYPE lvc_nkey,
l_node_key2 TYPE lvc_nkey,
l_node_key3 TYPE lvc_nkey,
l_node_text TYPE lvc_value,
l_relat_key TYPE lvc_nkey,
l_first_flg TYPE c.
DATA : l_handle_line TYPE i,
l_layout_node TYPE lvc_s_layn.
DATA : it_node_key TYPE lvc_t_nkey,
wa_node_key LIKE LINE OF it_node_key.
CLEAR : gt_sflight, gt_sflight[].
SELECT * FROM sflight INTO TABLE gt_itab
WHERE fldate BETWEEN '20190904' AND '20191004'.
l_relat_key = ''.
l_node_text = 'AIRPLANE'.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = l_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
IMPORTING
e_new_node_key = l_node_key.
APPEND l_node_key TO it_node_key.
SORT gt_itab BY carrid fldate.
LOOP AT gt_itab INTO ls_sflight.
AT NEW carrid.
l_relat_key = l_node_key.
l_node_text = ls_sflight-carrid.
l_first_flg = 'X'.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = l_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
* is_outtab_line = ls_sflight
IMPORTING
e_new_node_key = l_node_key2.
APPEND l_node_key2 TO it_node_key.
ENDAT.
IF l_first_flg = 'X'.
l_relat_key = l_node_key2.
l_node_text = ls_sflight-fldate.
l_first_flg = 'X'.
CALL METHOD g_line_behaviour->get_handle
IMPORTING
handle = l_handle_line.
* Assign drag and drop handle for each leaf:
l_layout_node-dragdropid = l_handle_line.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = l_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_sflight
is_node_layout = l_layout_node
IMPORTING
e_new_node_key = l_node_key3.
ENDIF.
AT END OF carrid.
CLEAR l_first_flg.
ENDAT.
ENDLOOP.
CALL METHOD g_alv_tree->expand_nodes
EXPORTING
it_node_key = it_node_key.
ENDFORM. " CREATE_HIERARCHY
*&---------------------------------------------------------------------*
*& Module PAI INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pai INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
PERFORM exit_program.
WHEN OTHERS.
* §6. Call dispatch to process toolbar functions
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
CALL METHOD cl_gui_cfw=>flush.
ENDMODULE. " PAI INPUT
*&---------------------------------------------------------------------*
*& Form EXIT_PROGRAM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM exit_program .
CALL METHOD g_custom_container->free.
LEAVE PROGRAM.
ENDFORM. " EXIT_PROGRAM
*&---------------------------------------------------------------------*
*& Form DEFINE_DND_BEHAVIOUR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM define_dnd_behaviour .
DATA: effect TYPE i, "#EC *
handle_alv TYPE i.
DATA handle_tree TYPE i.
CREATE OBJECT g_line_behaviour.
effect = cl_dragdrop=>move + cl_dragdrop=>copy.
CALL METHOD g_line_behaviour->add
EXPORTING
flavor = 'CARRID' "#EC NOTEXT
dragsrc = 'X'
droptarget = 'X'
effect = effect.
CALL METHOD g_line_behaviour->add
EXPORTING
flavor = 'flavor1'
dragsrc = 'X'
droptarget = space
effect = effect.
CALL METHOD g_line_behaviour->add
EXPORTING
flavor = 'flavor2'
dragsrc = 'X'
droptarget = space
effect = effect.
CREATE OBJECT g_fav_behaviour.
effect = cl_dragdrop=>move + cl_dragdrop=>copy.
CALL METHOD g_fav_behaviour->add
EXPORTING
flavor = 'flavor1'
dragsrc = space
droptarget = 'X'
effect = effect.
* CALL METHOD g_fav_behaviour->add
* EXPORTING
* flavor = 'flavor2'
* dragsrc = space
* droptarget = 'X'
* effect = effect.
CALL METHOD g_alv_tree->set_default_drop
EXPORTING
i_drag_drop = g_fav_behaviour.
CALL METHOD g_fav_behaviour->get_handle
IMPORTING
handle = handle_alv.
* CALL METHOD g_fav_behaviour->get_handle
* IMPORTING handle = handle_tree.
*
*
*
** DATA: effect TYPE i.
*
** §2. Define a behaviour for drag and drop on alv tree objects
*
** We need one behaviour for nodes of the last hierarchy level:
** It shall be possible to drag leaves in our hierarchy
** (marked by a plane icon)
* CREATE OBJECT g_line_behaviour.
* EFFECT = CL_DRAGDROP=>COPY .
** effect = cl_dragdrop=>move.
* CALL METHOD g_line_behaviour->add
* EXPORTING
* flavor = 'Start Date' "#EC NOTEXT
* dragsrc = ' '
* droptarget = 'X'
* effect = effect.
*
** The favourite folder shall allow to drop objects with
** flavor 'favorite'. No dragging is possible.
* CREATE OBJECT g_fav_behaviour.
* effect = cl_dragdrop=>COPY.
* CALL METHOD g_fav_behaviour->add
* EXPORTING
* flavor = 'Start Date' "#EC NOTEXT
* dragsrc = ' '
* droptarget = 'X'
* effect = effect.
*
* CALL METHOD g_alv_tree->set_default_drop
* EXPORTING
* i_drag_drop = g_fav_behaviour.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form REGISTER_EVENTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM register_events .
DATA: lt_events TYPE cntl_simple_events,
l_event TYPE cntl_simple_event,
l_dnd_event_receiver TYPE REF TO lcl_dnd_event_receiver.
*
** §7. Register events on backend (ABAP Objects event handling)
CREATE OBJECT l_dnd_event_receiver.
* SET HANDLER l_dnd_event_receiver->handle_fav_drop FOR g_alv_tree.
SET HANDLER l_dnd_event_receiver->handle_line_drag FOR g_alv_tree.
SET HANDLER l_dnd_event_receiver->on_drop FOR g_alv_tree.
SET HANDLER l_dnd_event_receiver->on_drop_com FOR g_alv_tree.
SET HANDLER l_dnd_event_receiver->on_checkbox_change FOR g_alv_tree.
* SET HANDLER l_dnd_event_receiver->on_node_keypress FOR g_alv_tree.
SET HANDLER l_dnd_event_receiver->on_link_click FOR g_alv_tree.
CALL METHOD g_alv_tree->get_registered_events
IMPORTING
events = lt_events.
l_event-appl_event = 'X'.
l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_node_keypress.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_link_click.
APPEND l_event TO lt_events.
CALL METHOD g_alv_tree->add_key_stroke
EXPORTING
i_key = cl_gui_column_tree=>key_f4.
CALL METHOD g_alv_tree->add_key_stroke
EXPORTING
i_key = cl_gui_column_tree=>key_enter.
CALL METHOD g_alv_tree->add_key_stroke
EXPORTING
i_key = cl_gui_column_tree=>key_copy.
CALL METHOD g_alv_tree->add_key_stroke
EXPORTING
i_key = cl_gui_column_tree=>key_paste.
CALL METHOD g_alv_tree->set_ctx_menu_select_event_appl
EXPORTING
i_appl_event = 'X'. "mit PAI
* register events on frontend
CALL METHOD g_alv_tree->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'.
ENDIF.
*--------------------
* DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.
* CREATE OBJECT l_event_receiver.
* SET HANDLER l_event_receiver->handle_item_double_click
* FOR g_alv_tree.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form ON_FUNCTION_SELECTED
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FCODE text
*----------------------------------------------------------------------*
FORM on_function_selected USING p_fcode.
DATA: l_node_key TYPE lvc_nkey,
lin TYPE i,
l_node_text TYPE lvc_value,
l_node_layout TYPE lvc_s_layn,
l_itab LIKE GT_itab.
DATA: lt_selected_nodes TYPE lvc_t_nkey,
ls_selected_node TYPE lvc_nkey.
DATA: l_top_key TYPE lvc_nkey,
l_new_key TYPE lvc_nkey.
CALL METHOD g_alv_tree->get_selected_nodes
CHANGING
ct_selected_nodes = lt_selected_nodes.
READ TABLE lt_selected_nodes INTO ls_selected_node INDEX 1.
drg_node-key = ls_selected_node.
CALL METHOD g_alv_tree->get_outtab_line
EXPORTING
i_node_key = drg_node-key
IMPORTING
e_outtab_line = l_itab
e_node_text = l_node_text
es_node_layout = l_node_layout
EXCEPTIONS
node_not_found = 1
OTHERS = 2.
CASE p_fcode.
WHEN 'SAVE'.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
CLEAR : gt_fieldcatalog. REFRESH : gt_fieldcatalog.
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
CLEAR : ls_fieldcatalog.
ls_fieldcatalog-fieldname = 'FLDATE'.
ls_fieldcatalog-reptext = 'DATE'.
APPEND ls_fieldcatalog TO gt_fieldcatalog.
CLEAR : ls_fieldcatalog.
ls_fieldcatalog-fieldname = 'CARRID'.
ls_fieldcatalog-reptext = 'CARRID'.
APPEND ls_fieldcatalog TO gt_fieldcatalog.
CLEAR : ls_fieldcatalog.
ls_fieldcatalog-fieldname = 'CONNID'.
ls_fieldcatalog-reptext = 'CONNID'.
APPEND ls_fieldcatalog TO gt_fieldcatalog.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form REGISTER_TOOLBAR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM register_toolbar .
DATA: toolbar_event_receiver TYPE REF TO lcl_toolbar_event_receiver.
* get toolbar control
CALL METHOD g_alv_tree->get_toolbar_object
IMPORTING
er_toolbar = mr_toolbar.
CHECK NOT mr_toolbar IS INITIAL.
CALL METHOD mr_toolbar->add_button
EXPORTING
fcode = 'SAVE'
icon = icon_system_save
butn_type = cntb_btype_button
text = 'Save'
quickinfo = 'Save Data'.
* set event-handler for toolbar-control
CREATE OBJECT toolbar_event_receiver.
SET HANDLER toolbar_event_receiver->on_function_selected
FOR mr_toolbar.
ENDFORM.
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
671 | 직원 데이터 [1] | sapjoy | 2024.07.02 | 241 |
670 | REPORT Z99_24. | sapjoy | 2024.05.21 | 83 |
669 | REPORT Z06_01. | sapjoy | 2024.04.21 | 60 |
668 | REPORT z05_36 | sapjoy | 2023.02.08 | 270 |
667 | API | sapjoy | 2022.11.03 | 351 |
666 | z15_21_drag | sapjoy | 2022.02.24 | 307 |
» | Z18_06_DRAGCLASS | sapjoy | 2022.02.23 | 334 |
664 | REPORT Z21_01 | sapjoy | 2015.10.28 | 2276 |
663 | subroutine pool | sapjoy | 2013.11.16 | 3314 |
662 | REPORT Z20_01. | sapjoy | 2012.08.02 | 5097 |
661 | REPORT Z19_02. | sapjoy | 2012.08.02 | 3953 |
660 | REPORT z19_01. | sapjoy | 2012.08.02 | 3559 |
659 | REPORT z18_06. | sapjoy | 2012.08.02 | 3195 |
658 | REPORT z18_05 | sapjoy | 2012.08.02 | 3384 |
657 | REPORT z18_04 . | sapjoy | 2012.08.02 | 3388 |
656 | REPORT z18_03. | sapjoy | 2012.08.02 | 4598 |
655 | REPORT z18_02. | sapjoy | 2012.08.02 | 3124 |
654 | REPORT z18_01. | sapjoy | 2012.08.02 | 3152 |
653 | REPORT z17_23 | sapjoy | 2012.08.02 | 2538 |
652 | REPORT z17_22 | sapjoy | 2012.08.02 | 2307 |