*DEFINATION
TABLES: ztmm004_01 .
TYPE-POOLS: slis.
CLASS lcl_application DEFINITION DEFERRED.
CLASS cl_gui_cfw DEFINITION LOAD.
DATA: g_application TYPE REF TO lcl_application.
TYPES: BEGIN OF gts_alv ,
box_fname TYPE c,
mode TYPE c.
INCLUDE STRUCTURE ztmm004_01 . "定义内表和工作区
TYPES: END OF gts_alv .
TYPES: BEGIN OF gts_mo ,
box_fname TYPE c,
mode TYPE c,
flag TYPE c,
zcyf TYPE ztmm004_01-zcyf, "承运方
zthfs TYPE ztmm004_01-zthfs, "提货方式
zcph TYPE ztmm004_01-zcph, "车牌号
zzcbz TYPE ztmm004_01-zzcbz, "装车班组
zckrp TYPE ztmm004_01-zckrp, "出库日期
zcksj TYPE ztmm004_01-zcksj, "出库时间
zckr TYPE ztmm004_01-zckr. "出库人
TYPES: END OF gts_mo .
DATA: mode TYPE c .
DATA: gt_data TYPE TABLE OF ztmm004_01,
gs_data TYPE ztmm004_01.
DATA: gt_alv TYPE TABLE OF gts_alv,
gs_alv TYPE gts_alv.
DATA: gv_bztm TYPE ztmm004_01-bztm .
DATA: gt_alv_ts TYPE TABLE OF gts_alv,
gs_alv_ts TYPE gts_alv.
DATA: gs_mo TYPE gts_mo.
"tree node table
TYPES: node_table_type LIKE STANDARD TABLE OF mtreesnode
WITH DEFAULT KEY.
DATA: gt_node TYPE node_table_type,
wa_node TYPE mtreesnode.
DATA: g_node_old TYPE tv_nodekey.
DATA: g_container TYPE REF TO cl_gui_custom_container,
g_tree TYPE REF TO cl_gui_simple_tree.
"物料主数据
TYPES: BEGIN OF ty_tab,
sel,
zgcms TYPE t001w-name1. "工厂描述
INCLUDE STRUCTURE zzxs_zsj_wlzsj.
TYPES: END OF ty_tab.
DATA: gt_tab TYPE TABLE OF ty_tab,
wa_tab TYPE ty_tab.
DATA: gt_tab_del TYPE TABLE OF ty_tab,
gt_tab_old TYPE TABLE OF ty_tab,
gt_tab_upload TYPE TABLE OF ty_tab.
"物料中类/物料小类
DATA: gt_wlzl TYPE TABLE OF zmm_zsj_wlzl_zx WITH HEADER LINE,
gt_wlxl TYPE TABLE OF zmm_zsj_wlxl_zx WITH HEADER LINE.
DATA: BEGIN OF wa_message,
msgty TYPE char4, "用红绿灯表示消息类型
matnr TYPE mara-matnr,
werks TYPE marc-werks,
msg TYPE string,
END OF wa_message.
DATA: gt_message LIKE TABLE OF wa_message.
DATA: g_alv TYPE REF TO cl_gui_alv_grid,
g_con TYPE REF TO cl_gui_custom_container.
*&SPWIZARD: DECLARATION OF TABLECONTROL 'TAB' ITSELF
CONTROLS: tab TYPE TABLEVIEW USING SCREEN 0100.
*&SPWIZARD: LINES OF TABLECONTROL 'TAB'
DATA: g_tab_lines LIKE sy-loopc.
DATA: g_excel TYPE ole2_object,
g_book TYPE ole2_object,
g_sheet TYPE ole2_object,
g_range TYPE ole2_object,
g_borders TYPE ole2_object,
g_rows TYPE ole2_object,
g_cell TYPE ole2_object,
g_columns TYPE ole2_object,
g_sheet_number TYPE i.
DATA: ok_code LIKE sy-ucomm,
ok_save TYPE sy-ucomm.
*----------------------------------------------------------------------*
* CLASS lcl_application DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_application DEFINITION.
PUBLIC SECTION.
METHODS:
handle_node_double_click
FOR EVENT node_double_click
OF cl_gui_simple_tree
IMPORTING node_key,
handle_node_selection
FOR EVENT selection_changed
OF cl_gui_simple_tree
IMPORTING node_key.
ENDCLASS. "lcl_application DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_application IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_application IMPLEMENTATION.
METHOD handle_node_double_click.
"使用selection_changed 事件, 不再使用双击事件
"PERFORM frm_node_double_click USING node_key.
ENDMETHOD. "handle_node_double_click
METHOD handle_node_selection.
* PERFORM frm_node_selection USING node_key.
ENDMETHOD. "handle_node_selection
ENDCLASS. "lcl_application IMPLEMENTATION
*SCREEN 100
PROCESS BEFORE OUTPUT.
*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'TC_CTRL'
MODULE tc_ctrl_change_tc_attr.
*&SPWIZARD: MODULE TC_CTRL_CHANGE_COL_ATTR.
LOOP AT gt_alv
INTO gs_alv
WITH CONTROL tc_ctrl
CURSOR tc_ctrl-current_line.
MODULE tc_ctrl_get_lines.
*&SPWIZARD: MODULE TC_CTRL_CHANGE_FIELD_ATTR
ENDLOOP.
MODULE status_0100.
MODULE init_0100.
*
PROCESS AFTER INPUT.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TC_CTRL'
LOOP AT gt_alv.
CHAIN.
FIELD gs_alv-mode.
FIELD gs_alv-bztm.
FIELD gs_alv-vbeln.
FIELD gs_alv-posnr.
FIELD gs_alv-wlxl.
FIELD gs_alv-bjbz.
FIELD gs_alv-hbtm.
FIELD gs_alv-zcyf.
FIELD gs_alv-zthfs.
FIELD gs_alv-zcph.
FIELD gs_alv-zzcbz.
FIELD gs_alv-zckrp.
FIELD gs_alv-zcksj.
FIELD gs_alv-zckr.
MODULE tc_ctrl_modify ON CHAIN-REQUEST.
ENDCHAIN.
* FIELD gs_alv-box_fname
* MODULE tc_ctrl_mark ON REQUEST.
ENDLOOP.
*在PBO中添加TREE对象
MODULE init_0100 OUTPUT.
"初始化树对象
IF g_tree IS INITIAL.
PERFORM frm_init_tree.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form FRM_INIT_TREE
*&---------------------------------------------------------------------*
*& 初始化树对象
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_init_tree .
DATA l_hierarchy_header TYPE treev_hhdr.
DATA: events TYPE cntl_simple_events,
event TYPE cntl_simple_event.
* Create container and alv tree object
CREATE OBJECT g_container
EXPORTING
container_name = 'TREE_CONTAINER'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
CHECK sy-subrc = 0.
CREATE OBJECT g_tree
EXPORTING
* lifetime =
parent = g_container
* shellstyle =
node_selection_mode = g_tree->node_sel_mode_single
* hide_selection =
* name =
EXCEPTIONS
lifetime_error = 1
cntl_system_error = 2
create_error = 3
failed = 4
illegal_node_selection_mode = 5
OTHERS = 6.
CHECK sy-subrc = 0.
CALL METHOD g_tree->set_alignment
EXPORTING
alignment = 15.
"注册双击事件
* event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
* event-appl_event = 'X'. "
* APPEND event TO events.
event-eventid = cl_gui_simple_tree=>eventid_selection_changed.
event-appl_event = 'X'. "
APPEND event TO events.
CALL METHOD g_tree->set_registered_events
EXPORTING
events = events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc <> 0.
ENDIF.
CREATE OBJECT g_application.
"SET HANDLER g_application->handle_node_double_click FOR g_tree.
SET HANDLER g_application->handle_node_selection FOR g_tree.
"设置node
REFRESH gt_node.
PERFORM frm_node_table.
CALL METHOD g_tree->add_nodes
EXPORTING
table_structure_name = 'MTREESNODE'
node_table = gt_node
EXCEPTIONS
failed = 1
error_in_node_table = 2
dp_error = 3
table_structure_name_not_found = 4
OTHERS = 5.
IF sy-subrc <> 0.
*
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_NODE_TABLE
*&---------------------------------------------------------------------*
* 设置节点表数据
*----------------------------------------------------------------------*
FORM frm_node_table .
"第一层节点'
CLEAR wa_node.
wa_node-node_key = 'ROOT'.
wa_node-text = '存货分类'.
wa_node-isfolder = 'X'.
APPEND wa_node TO gt_node.
"第二层节点(物料中类)
REFRESH gt_wlzl.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_wlzl
FROM zmm_zsj_wlzl_zx.
LOOP AT gt_wlzl.
CLEAR wa_node.
wa_node-node_key = gt_wlzl-zwlzl.
CONCATENATE '(' gt_wlzl-zwlzl ')' INTO wa_node-text.
CONCATENATE wa_node-text gt_wlzl-zms INTO wa_node-text SEPARATED BY space.
wa_node-isfolder = 'X'.
wa_node-relatkey = 'ROOT'.
wa_node-relatship = cl_gui_simple_tree=>relat_last_child.
APPEND wa_node TO gt_node.
ENDLOOP.
"第三层节点(物料小类)
REFRESH gt_wlxl.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_wlxl
FROM zmm_zsj_wlxl_zx.
LOOP AT gt_wlxl.
CLEAR wa_node.
wa_node-node_key = gt_wlxl-zwlxl.
CONCATENATE '(' gt_wlxl-zwlxl ')' INTO wa_node-text.
CONCATENATE wa_node-text gt_wlxl-zms INTO wa_node-text SEPARATED BY space.
wa_node-relatkey = gt_wlxl-zwlzl.
wa_node-relatship = cl_gui_simple_tree=>relat_last_child.
APPEND wa_node TO gt_node.
ENDLOOP.
ENDFORM. " FRM_NODE_TABLE
显示效果: