实现方法
代码
代码语言:javascript复制 CLASS lcl_events_receiver DEFINITION DEFERRED.
TABLES: zmm_ap_po_head.
TYPES: BEGIN OF ty_zmm_ap_po_head,
box TYPE c.
INCLUDE STRUCTURE zmm_ap_po_head.
TYPES: END OF ty_zmm_ap_po_head.
TYPES: BEGIN OF ty_zmm_ap_po_item,
box TYPE c.
INCLUDE STRUCTURE zmm_ap_po_item.
TYPES: END OF ty_zmm_ap_po_item.
DATA: sellist TYPE TABLE OF vimsellist,
wa_sellist TYPE vimsellist.
DATA: go_customer_container TYPE REF TO cl_gui_custom_container,
go_split TYPE REF TO cl_gui_splitter_container,
go_grid_head TYPE REF TO cl_gui_alv_grid,
go_grid_item TYPE REF TO cl_gui_alv_grid.
DATA: gt_zmm_ap_po_head TYPE TABLE OF ty_zmm_ap_po_head,
gt_zmm_ap_po_item TYPE TABLE OF ty_zmm_ap_po_item.
DATA: gr_table_head TYPE REF TO cl_salv_table,
gr_table_item TYPE REF TO cl_salv_table.
DATA: go_columns TYPE REF TO cl_salv_columns.
DATA: gs_layout TYPE lvc_s_layo, "布局
gt_fieldcat TYPE lvc_t_fcat, "字段属性内表
gt_fieldcat_head TYPE lvc_t_fcat, "字段属性内表
gt_fieldcat_item TYPE lvc_t_fcat, "字段属性内表
gs_fieldcat TYPE lvc_s_fcat,
gs_ui_func TYPE ui_func, "隐藏工具栏图标
gt_ui_func TYPE ui_functions,
gv_col TYPE i.
DATA: go_events_receiver TYPE REF TO lcl_events_receiver.
CONSTANTS: lc_appid TYPE string VALUE 'dcfa5c7d-cef8-8837-a49f-6f1d92adf792'.
*----------------------------------------------------------------------*
* CLASS lcl_events_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_events_receiver DEFINITION .
PUBLIC SECTION.
"工具栏事件
METHODS toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object.
"处理命令事件
METHODS user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
"数据改变事件
METHODS data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
METHODS data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified.
"单击事件
METHODS hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id.
"双击事件
METHODS double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column.
ENDCLASS. "LCL_EVENTS_RECEIVER DEFINITION
"事件接收类实现
*----------------------------------------------------------------------*
* CLASS LCL_EVENTS_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_events_receiver IMPLEMENTATION.
"工具栏事件实现
METHOD toolbar.
PERFORM frm_toolbar USING e_object.
ENDMETHOD. "TOOLBAR
"处理命令事件实现
METHOD user_command.
PERFORM frm_user_command USING e_ucomm.
ENDMETHOD. "USER_COMMAND
METHOD data_changed_finished .
PERFORM frm_data_changed_finished USING e_modified .
ENDMETHOD . "handle_data_changed_finished
"数据改变事件实现
METHOD data_changed.
* PERFORM frm_data_changed USING er_data_changed.
ENDMETHOD. "DATA_CHANGED
"单击事件实现
METHOD hotspot_click.
* PERFORM frm_hotspot_click USING e_row_id e_column_id.
ENDMETHOD. "HOTSPOT_CLICK
"双击事件
METHOD double_click.
* PERFORM frm_double_click USING e_row e_column.
ENDMETHOD. "DOUBLE_CLICK
ENDCLASS. "LCL_EVENTS_RECEIVER IMPLEMENTATION
DEFINE marco_sellist.
wa_sellist-viewfield = &1.
wa_sellist-operator = &2.
wa_sellist-value = &3.
wa_sellist-and_or = &4.
append wa_sellist to sellist.
clear wa_sellist.
END-OF-DEFINITION.
DEFINE m_fieldcat.
clear gs_fieldcat.
gs_fieldcat-fieldname = &1.
gs_fieldcat-ref_table = &2.
gs_fieldcat-ref_field = &3.
gs_fieldcat-scrtext_s = &4.
gs_fieldcat-scrtext_m = &4.
gs_fieldcat-scrtext_l = &4.
gv_col = gv_col 1.
gs_fieldcat-col_pos = gv_col.
if &1 eq 'BOX'.
if &5 = 'X'.
gs_fieldcat-edit = 'X'.
endif.
gs_fieldcat-checkbox = 'X'.
endif.
append gs_fieldcat to gt_fieldcat.
END-OF-DEFINITION.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_sync TYPE c RADIOBUTTON GROUP g1 USER-COMMAND ucomm DEFAULT'X',
p_send TYPE c RADIOBUTTON GROUP g1,
p_reset TYPE c RADIOBUTTON GROUP g1,
p_query TYPE c RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_fm1 TYPE c MODIF ID m1 DEFAULT'X' USER-COMMAND fm.",
* p_fm2 TYPE c RADIOBUTTON GROUP g2 MODIF ID m1.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
SELECT-OPTIONS: s1_ebeln FOR zmm_ap_po_head-ebeln MODIF ID m2,
s1_bsart FOR zmm_ap_po_head-bsart MODIF ID m2,
s1_bukrs FOR zmm_ap_po_head-bukrs MODIF ID m2,
s1_lifnr FOR zmm_ap_po_head-lifnr MODIF ID m2,
s1_zterm FOR zmm_ap_po_head-zterm MODIF ID m2,
s1_aedat FOR zmm_ap_po_head-aedat MODIF ID m2,
s1_ernam FOR zmm_ap_po_head-ernam MODIF ID m2,
s1_loekz FOR zmm_ap_po_head-loekz MODIF ID m2,
s1_zcdat FOR zmm_ap_po_head-zcdate MODIF ID m2,
s1_zctim FOR zmm_ap_po_head-zctime MODIF ID m2,
s1_type FOR zmm_ap_po_head-type MODIF ID m2,
s1_msg FOR zmm_ap_po_head-message MODIF ID m2,
s1_zupmo FOR zmm_ap_po_head-zupmod NO INTERVALS MODIF ID m3,
s1_zupfl FOR zmm_ap_po_head-zupflg NO INTERVALS MODIF ID m4.
PARAMETERS: p_max TYPE tbmaxsel MODIF ID mi OBLIGATORY DEFAULT 500.
SELECTION-SCREEN END OF BLOCK b3.
INITIALIZATION.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF p_fm1 = 'X'.
IF p_query = 'X' AND screen-group1 = 'MI'.
screen-active = 1.
ELSEIF screen-group1 = 'MI'.
screen-active = 0.
ENDIF.
CASE 'X'.
WHEN p_sync. "后台同步
IF screen-group1 = 'M2' OR screen-group1 = 'M3' OR screen-group1 = 'M4'.
screen-active = 0.
ENDIF.
WHEN p_reset. "重置传输标识
WHEN p_send. "手动同步
IF screen-group1 = 'M3'.
screen-input = 0.
ENDIF.
WHEN p_query. "查询
WHEN OTHERS.
ENDCASE.
* ELSEIF p_fm2 = 'X'.
* IF screen-group1 = 'M2' OR screen-group1 = 'M3'.
* screen-active = 0.
* ELSEIF p_query = 'X' AND screen-group1 = 'MI'.
* screen-active = 1.
* ELSEIF screen-group1 = 'MI'.
* screen-active = 0.
* ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'UCOMM'.
IF p_send = 'X'.
s1_zupmo-sign = 'I'.
s1_zupmo-option = 'EQ'.
s1_zupmo-low = '2'.
APPEND s1_zupmo.
CLEAR: s1_zupfl,s1_zupfl[].
ELSEIF p_reset = 'X'.
CLEAR: s1_zupfl,s1_zupfl[],s1_zupmo,s1_zupmo[].
ELSE.
CLEAR: s1_zupmo,s1_zupmo[].
ENDIF.
ENDCASE.
PERFORM frm_check_author.
START-OF-SELECTION.
IF p_fm1 = 'X'. "采购订单业务
CASE 'X'.
WHEN p_sync. "后台同步
PERFORM frm_syncdata_to_oa_fm1.
WHEN p_reset. "重置传输标识
PERFORM frm_reset_fm1.
WHEN p_query OR p_send. "查询 & 手动同步
PERFORM frm_query_fm1.
WHEN OTHERS.
ENDCASE.
* ELSEIF p_fm2 = 'X'. "收货凭证业务
* CASE 'X'.
* WHEN p_sync. "后台同步
** PERFORM frm_syncdata_to_oa_FM2.
* WHEN p_reset. "重置传输标识
** PERFORM frm_reset_fm2.
* WHEN p_query OR p_send. "查询 & 手动同步
** PERFORM frm_query_fm2.
* WHEN OTHERS.
* ENDCASE.
ENDIF.
END-OF-SELECTION.
CASE 'X'.
WHEN p_query OR p_send. "查询 & 手动同步
CALL SCREEN 9000.
ENDCASE.
*&---------------------------------------------------------------------*
*& Form frm_reset_fm1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_reset_fm1 .
* marco_sellist: 'ZUPFLG' 'EQ' p2_ZUPFL 'AND'.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'ZUPFLG'
TABLES
sellist = sellist
rangetab = s1_zupfl.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'ZUPMOD'
TABLES
sellist = sellist
rangetab = s1_zupmo.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'EBELN'
TABLES
sellist = sellist
rangetab = s1_ebeln.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'BSART'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_bsart.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'BUKRS'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_bukrs.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'LIFNR'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_lifnr.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'ZTERM'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_zterm.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'AEDAT'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_aedat.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'ERNAM'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_ernam.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'LOEKZ'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_loekz.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'ZCDATE'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_zcdat.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'ZCTIME'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_zctim.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'TYPE'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_type.
CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'
EXPORTING
fieldname = 'MESSAGE'
append_conjunction = 'AND'
TABLES
sellist = sellist
rangetab = s1_msg.
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
action = 'U'
* CORR_NUMBER = ' '
* GENERATE_MAINT_TOOL_IF_MISSING = ' '
* SHOW_SELECTION_POPUP = ' '
view_name = 'ZMM_AP_PO_HEAD'
* NO_WARNING_FOR_CLIENTINDEP = ' '
* RFC_DESTINATION_FOR_UPGRADE = ' '
* CLIENT_FOR_UPGRADE = ' '
* VARIANT_FOR_SELECTION = ' '
complex_selconds_used = 'X'
* CHECK_DDIC_MAINFLAG = ' '
* SUPPRESS_WA_POPUP = ' '
TABLES
dba_sellist = sellist
EXCEPTIONS
client_reference = 1
foreign_lock = 2
invalid_action = 3
no_clientindependent_auth = 4
no_database_function = 5
no_editor_function = 6
no_show_auth = 7
no_tvdir_entry = 8
no_upd_auth = 9
only_show_allowed = 10
system_failure = 11
unknown_field_in_dba_sellist = 12
view_not_found = 13
maintenance_prohibited = 14
OTHERS = 15.
ENDFORM. " FRM_RESET_FM1
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_AUTHOR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_check_author .
DATA: lt_t001 TYPE TABLE OF t001,
wa_t001 TYPE t001.
SELECT * FROM t001 INTO TABLE lt_t001 WHERE bukrs IN s1_bukrs.
LOOP AT lt_t001 INTO wa_t001.
zcl_common_authority_check=>check_bukrs( EXPORTING iv_bukrs = wa_t001-bukrs ).
ENDLOOP.
ENDFORM. " FRM_CHECK_AUTHOR
*&---------------------------------------------------------------------*
*& Form FRM_QUERY_FM1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_query_fm1 .
PERFORM frm_init_object_fm1.
PERFORM frm_set_layout_fm1.
PERFORM frm_set_fieldcat_fm1.
PERFORM frm_excluding_toolbar_fm1.
PERFORM frm_get_data_fm1.
PERFORM frm_show_data_fm1.
ENDFORM. "FRM_QUERY_FM1
*&---------------------------------------------------------------------*
*& Form frm_init_object_fm1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_init_object_fm1 .
"初始化GRID ALV对象
IF go_customer_container IS INITIAL.
CREATE OBJECT go_customer_container
EXPORTING
container_name = 'CONTAINER_ROOT'.
ENDIF.
IF go_split IS INITIAL.
CREATE OBJECT go_split
EXPORTING
parent = go_customer_container
rows = 2
columns = 1.
ENDIF.
IF go_grid_head IS INITIAL.
CREATE OBJECT go_grid_head
EXPORTING
i_parent = go_split->get_container( row = 1 column = 1 ).
ENDIF.
IF go_grid_item IS INITIAL.
CREATE OBJECT go_grid_item
EXPORTING
i_parent = go_split->get_container( row = 2 column = 1 ).
ENDIF.
ENDFORM. " frm_init_object_fm1
*&---------------------------------------------------------------------*
*& Form frm_get_data_fm1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_get_data_fm1 .
IF p_query = 'X'.
SELECT *
FROM zmm_ap_po_head
INTO CORRESPONDING FIELDS OF TABLE gt_zmm_ap_po_head
UP TO p_max ROWS
WHERE ebeln IN s1_ebeln
AND bsart IN s1_bsart
AND bukrs IN s1_bukrs
AND lifnr IN s1_lifnr
AND zterm IN s1_zterm
AND aedat IN s1_aedat
AND ernam IN s1_ernam
AND loekz IN s1_loekz.
ELSE.
SELECT *
FROM zmm_ap_po_head
INTO CORRESPONDING FIELDS OF TABLE gt_zmm_ap_po_head
WHERE ebeln IN s1_ebeln
AND bsart IN s1_bsart
AND bukrs IN s1_bukrs
AND lifnr IN s1_lifnr
AND zterm IN s1_zterm
AND aedat IN s1_aedat
AND ernam IN s1_ernam
AND loekz IN s1_loekz
AND zupmod IN s1_zupmo
AND zupflg IN s1_zupfl.
ENDIF.
IF gt_zmm_ap_po_head IS NOT INITIAL.
SELECT *
FROM zmm_ap_po_item
INTO CORRESPONDING FIELDS OF TABLE gt_zmm_ap_po_item
FOR ALL ENTRIES IN gt_zmm_ap_po_head
WHERE ebeln = gt_zmm_ap_po_head-ebeln.
ENDIF.
SORT gt_zmm_ap_po_head BY ebeln ASCENDING.
SORT gt_zmm_ap_po_item BY ebeln ebelp ASCENDING.
ENDFORM. " frm_get_data_fm1
*&---------------------------------------------------------------------*
*& Form FRM_SHOW_DATA_FM1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_show_data_fm1 .
"实例化事件对象
CREATE OBJECT go_events_receiver.
"注册事件
SET HANDLER go_events_receiver->toolbar FOR go_grid_head.
SET HANDLER go_events_receiver->user_command FOR go_grid_head.
SET HANDLER go_events_receiver->data_changed FOR go_grid_head.
SET HANDLER go_events_receiver->data_changed_finished FOR go_grid_head.
SET HANDLER go_events_receiver->hotspot_click FOR go_grid_head.
SET HANDLER go_events_receiver->double_click FOR go_grid_head.
CALL METHOD go_grid_head->register_edit_event "注册编辑事件响应Checkbox
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD go_grid_head->set_table_for_first_display
EXPORTING
i_save = 'A'
i_default = 'X'
is_layout = gs_layout
it_toolbar_excluding = gt_ui_func
CHANGING
it_outtab = gt_zmm_ap_po_head
it_fieldcatalog = gt_fieldcat_head
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
"注册事件
*SET HANDLER go_events_receiver->toolbar FOR go_grid_item.
SET HANDLER go_events_receiver->user_command FOR go_grid_item.
SET HANDLER go_events_receiver->data_changed FOR go_grid_item.
SET HANDLER go_events_receiver->data_changed_finished FOR go_grid_item.
SET HANDLER go_events_receiver->hotspot_click FOR go_grid_item.
SET HANDLER go_events_receiver->double_click FOR go_grid_item.
CALL METHOD go_grid_item->set_table_for_first_display
EXPORTING
i_save = 'A'
i_default = 'X'
is_layout = gs_layout
it_toolbar_excluding = gt_ui_func
CHANGING
it_outtab = gt_zmm_ap_po_item
it_fieldcatalog = gt_fieldcat_item
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM. " FRM_SHOW_DATA_FM1
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
DATA: l_text TYPE char100.
IF p_fm1 = 'X' AND p_query = 'X'.
l_text = '显示下传OA的销售订单数据!'.
ELSEIF p_fm1 = 'X' AND p_send = 'X'.
l_text = '手工下传销售订单到OA!'.
* ELSEIF p_fm2 = 'X' AND p_query = 'X'.
* l_text = '显示下传OA的收货凭证数据!'.
* ELSEIF p_fm2 = 'X' AND p_send = 'X'.
* l_text = '手工下传收货凭证到OA!'.
ENDIF.
SET PF-STATUS '9000'.
SET TITLEBAR '9000' WITH l_text.
ENDMODULE. " STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
DATA lv_ucomm TYPE sy-ucomm.
lv_ucomm = sy-ucomm.
CASE lv_ucomm.
WHEN '&F03' OR '&F12' OR '&F15'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
*& Form frm_set_layout_fm1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_set_layout_fm1 .
CLEAR: gs_layout.
gs_layout-cwidth_opt = 'X'. "自动列宽
gs_layout-zebra = 'X'. "斑马纹
* gs_layout-box_fname = 'BOX'.
* gs_layout-sel_mode = 'A'. "显示选择块
* GS_LAYOUT-EDIT = 'X'.
gs_layout-detailinit = 'X'.
gs_layout-detailtitl = '详细信息'.
* GS_LAYOUT-STYLEFNAME = 'ZSTYLE'. "用于改变字段属性
ENDFORM. " frm_set_layout_fm1
*&---------------------------------------------------------------------*
*& Form frm_set_fieldcat_fm1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_set_fieldcat_fm1 .
m_fieldcat: 'BOX' '' '' '选择' 'X'.
m_fieldcat: 'EBELN' 'ZMM_AP_PO_HEAD' 'EBELN' '采购凭证号' ''.
m_fieldcat: 'BSART' 'ZMM_AP_PO_HEAD' 'BSART' '采购凭证类型' ''.
m_fieldcat: 'BUKRS' 'ZMM_AP_PO_HEAD' 'BUKRS' '公司代码' ''.
m_fieldcat: 'BUTXT' 'ZMM_AP_PO_HEAD' 'BUTXT' '公司代码的名称' ''.
m_fieldcat: 'WAERS' 'ZMM_AP_PO_HEAD' 'WAERS' '货币码' ''.
m_fieldcat: 'LIFNR' 'ZMM_AP_PO_HEAD' 'LIFNR' '供应商代码' ''.
m_fieldcat: 'NAME1' 'ZMM_AP_PO_HEAD' 'NAME1' '供应商名称' ''.
m_fieldcat: 'ZTERM' 'ZMM_AP_PO_HEAD' 'ZTERM' '付款条件代码' ''.
m_fieldcat: 'TEXT1' 'ZMM_AP_PO_HEAD' 'TEXT1' '付款条件描述' ''.
m_fieldcat: 'ZDDHSZJ' 'ZMM_AP_PO_HEAD' 'ZDDHSZJ' '整单含税总价' ''.
m_fieldcat: 'AEDAT' 'ZMM_AP_PO_HEAD' 'AEDAT' '创建日期' ''.
m_fieldcat: 'ERNAM' 'ZMM_AP_PO_HEAD' 'ERNAM' '创建人' ''.
m_fieldcat: 'NAME_TEXT' 'ZMM_AP_PO_HEAD' 'NAME_TEXT' '创建人名称' ''.
m_fieldcat: 'LOEKZ' 'ZMM_AP_PO_HEAD' 'LOEKZ' '删除标识' ''.
m_fieldcat: 'ZUPMOD' 'ZMM_AP_PO_HEAD' 'ZUPMOD' '更新模式' ''.
m_fieldcat: 'ZUPFLG' 'ZMM_AP_PO_HEAD' 'ZUPFLG' '更新标识' ''.
m_fieldcat: 'ZCDATE' 'ZMM_AP_PO_HEAD' 'ZCDATE' '上次同步日期' ''.
m_fieldcat: 'ZCTIME' 'ZMM_AP_PO_HEAD' 'ZCTIME' '上次同步时间' ''.
m_fieldcat: 'TYPE' 'ZMM_AP_PO_HEAD' 'TYPE' '信息类型' ''.
m_fieldcat: 'MESSAGE' 'ZMM_AP_PO_HEAD' 'MESSAGE' '消息文本' ''.
gt_fieldcat_head = gt_fieldcat.
CLEAR gv_col.
REFRESH gt_fieldcat.
m_fieldcat: 'BOX' '' '' '选择' ''.
m_fieldcat: 'EBELN' 'ZMM_AP_PO_ITEM' 'EBELN' '采购凭证号' ''.
m_fieldcat: 'EBELP' 'ZMM_AP_PO_ITEM' 'EBELP' '采购凭证项目' ''.
m_fieldcat: 'WERKS' 'ZMM_AP_PO_ITEM' 'WERKS' '工厂' ''.
m_fieldcat: 'NAME1' 'ZMM_AP_PO_ITEM' 'NAME1' '工厂名称' ''.
m_fieldcat: 'MTART' 'ZMM_AP_PO_ITEM' 'MTART' '商品类型' ''.
m_fieldcat: 'MTBEZ' 'ZMM_AP_PO_ITEM' 'MTBEZ' '商品类型描述' ''.
m_fieldcat: 'MATNR' 'ZMM_AP_PO_ITEM' 'MATNR' '物料编码' ''.
m_fieldcat: 'TXZ01' 'ZMM_AP_PO_ITEM' 'TXZ01' '物料描述' ''.
m_fieldcat: 'MEINS' 'ZMM_AP_PO_ITEM' 'MEINS' '采购订单计计量单位' ''.
m_fieldcat: 'MWSKZ' 'ZMM_AP_PO_ITEM' 'MWSKZ' '进项税代码' ''.
m_fieldcat: 'MENGE' 'ZMM_AP_PO_ITEM' 'MENGE' '采购订单数量' ''.
m_fieldcat: 'NETPR' 'ZMM_AP_PO_ITEM' 'NETPR' '净价' ''.
m_fieldcat: 'NETWR' 'ZMM_AP_PO_ITEM' 'NETWR' '订单净值' ''.
m_fieldcat: 'ZHSDJ' 'ZMM_AP_PO_ITEM' 'ZHSDJ' '含税单价' ''.
m_fieldcat: 'BONBA' 'ZMM_AP_PO_ITEM' 'BONBA' '含税总价' ''.
m_fieldcat: 'EINDT' 'ZMM_AP_PO_ITEM' 'EINDT' '项目交货日期' ''.
m_fieldcat: 'PRDAT' 'ZMM_AP_PO_ITEM' 'PRDAT' '价格确定日期' ''.
m_fieldcat: 'LOEKZ' 'ZMM_AP_PO_ITEM' 'LOEKZ' '删除标识' ''.
gt_fieldcat_item = gt_fieldcat.
CLEAR gv_col.
REFRESH gt_fieldcat.
ENDFORM. " frm_set_fieldcat_fm1
*&---------------------------------------------------------------------*
*& Form FRM_DATA_CHANGED_FINISHED
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_E_MODIFIED text
*----------------------------------------------------------------------*
FORM frm_data_changed_finished USING p_e_modified.
DATA: is_stable TYPE lvc_s_stbl.
DATA: ls_row_id TYPE lvc_s_row.
FIELD-SYMBOLS: <fs_zmm_ap_po_head> TYPE ty_zmm_ap_po_head,
<fs_zmm_ap_po_item> TYPE ty_zmm_ap_po_item.
CALL METHOD go_grid_head->get_current_cell
IMPORTING
es_row_id = ls_row_id.
READ TABLE gt_zmm_ap_po_head ASSIGNING <fs_zmm_ap_po_head> INDEX ls_row_id.
IF sy-subrc = 0.
LOOP AT gt_zmm_ap_po_item ASSIGNING <fs_zmm_ap_po_item> WHERE ebeln = <fs_zmm_ap_po_head>-ebeln.
<fs_zmm_ap_po_item>-box = <fs_zmm_ap_po_head>-box.
ENDLOOP.
ENDIF.
is_stable-row = 'X'. "保持行
is_stable-col = 'X'. "保持列
CALL METHOD go_grid_head->refresh_table_display( EXPORTING is_stable = is_stable ).
CALL METHOD go_grid_item->refresh_table_display( EXPORTING is_stable = is_stable ).
ENDFORM. " FRM_DATA_CHANGED_FINISHED
*&---------------------------------------------------------------------*
*& Form frm_excluding_toolbar_fm1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_excluding_toolbar_fm1 .
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_append_row. "附加行
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_insert_row."插入行
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_delete_row."删除行
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_copy.
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_copy_row."复制行
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_cut.
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_move_row.
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_paste.
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_loc_undo.
APPEND gs_ui_func TO gt_ui_func.
gs_ui_func = cl_gui_alv_grid=>mc_fc_info. "文本信息
APPEND gs_ui_func TO gt_ui_func.
ENDFORM. " frm_excluding_toolbar_fm1
*&---------------------------------------------------------------------*
*& Form FRM_USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_E_UCOMM text
*----------------------------------------------------------------------*
FORM frm_user_command USING p_e_ucomm.
DATA: l_answer TYPE c,
is_stable TYPE lvc_s_stbl.
FIELD-SYMBOLS: <fs_zmm_ap_po_head> TYPE ty_zmm_ap_po_head, "手工同步选择的数据
<fs_zmm_ap_po_item> TYPE ty_zmm_ap_po_item.
CASE p_e_ucomm.
WHEN 'ZPOST'.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = '是否立即执行同步'
IMPORTING
answer = l_answer.
IF l_answer = '1'.
PERFORM frm_syncdata_to_oa_fm1.
ENDIF.
WHEN 'ZSELALL'.
LOOP AT gt_zmm_ap_po_head ASSIGNING <fs_zmm_ap_po_head> WHERE box NE 'X'.
<fs_zmm_ap_po_head>-box = 'X'.
ENDLOOP.
LOOP AT gt_zmm_ap_po_item ASSIGNING <fs_zmm_ap_po_item> WHERE box NE 'X'.
<fs_zmm_ap_po_item>-box = 'X'.
ENDLOOP.
WHEN 'ZDESELALL'.
LOOP AT gt_zmm_ap_po_head ASSIGNING <fs_zmm_ap_po_head> WHERE box = 'X'.
CLEAR <fs_zmm_ap_po_head>-box.
ENDLOOP.
LOOP AT gt_zmm_ap_po_item ASSIGNING <fs_zmm_ap_po_item> WHERE box = 'X'.
CLEAR <fs_zmm_ap_po_item>-box.
ENDLOOP.
WHEN OTHERS.
ENDCASE.
is_stable-row = 'X'. "保持行
is_stable-col = 'X'. "保持列
CALL METHOD go_grid_head->refresh_table_display( EXPORTING is_stable = is_stable ).
CALL METHOD go_grid_item->refresh_table_display( EXPORTING is_stable = is_stable ).
ENDFORM. " FRM_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form FRM_TOOLBAR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_E_OBJECT text
*----------------------------------------------------------------------*
FORM frm_toolbar USING p_object TYPE REF TO cl_alv_event_toolbar_set.
DATA: ls_toolbar TYPE stb_button.
"插入分隔符
CLEAR ls_toolbar.
ls_toolbar-butn_type = 3.
APPEND ls_toolbar TO p_object->mt_toolbar.
CLEAR ls_toolbar.
ls_toolbar-function = 'ZSELALL'. "function code
ls_toolbar-icon = icon_select_all.
ls_toolbar-quickinfo = '全选'. "按钮信息 鼠标停在按钮上显示的信息
ls_toolbar-butn_type = 0. "按钮类型
IF p_send = 'X'.
ls_toolbar-disabled = ''.
ELSE.
ls_toolbar-disabled = 'X'.
ENDIF.
ls_toolbar-text = '全选'. "按钮名称
APPEND ls_toolbar TO p_object->mt_toolbar.
CLEAR ls_toolbar.
ls_toolbar-function = 'ZDESELALL'. "function code
ls_toolbar-icon = icon_deselect_all.
ls_toolbar-quickinfo = '取消全选'. "按钮信息 鼠标停在按钮上显示的信息
ls_toolbar-butn_type = 0. "按钮类型
IF p_send = 'X'.
ls_toolbar-disabled = ''.
ELSE.
ls_toolbar-disabled = 'X'.
ENDIF.
ls_toolbar-text = '取消全选'. "按钮名称
APPEND ls_toolbar TO p_object->mt_toolbar.
CLEAR ls_toolbar.
ls_toolbar-function = 'ZPOST'. "function code
ls_toolbar-icon = icon_execute_object.
ls_toolbar-quickinfo = '手工同步数据到OA'. "按钮信息 鼠标停在按钮上显示的信息
ls_toolbar-butn_type = 0. "按钮类型
IF p_send = 'X'.
ls_toolbar-disabled = ''.
ELSE.
ls_toolbar-disabled = 'X'.
ENDIF.
ls_toolbar-text = '同步数据到OA'. "按钮名称
APPEND ls_toolbar TO p_object->mt_toolbar.
ENDFORM. " FRM_TOOLBAR
*&---------------------------------------------------------------------*
*& Form FRM_SYNCDATA_OA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_syncdata_to_oa_fm1 .
DATA: ls_output TYPE zpi_mt_oa_003_output,
ls_input TYPE zpi_mt_oa_003_input.
DATA: l_string TYPE string.
DATA: l_javascript_code TYPE string,
lo_javascript TYPE REF TO cl_java_script.
DATA: ls_hash TYPE md5_fields-hash.
DATA: lt_db_head TYPE TABLE OF zmm_ap_po_head, "head缓存表,用于向数据库回写数据
wa_db_head TYPE zmm_ap_po_head,
lt_db_items TYPE TABLE OF zmm_ap_po_item, "item缓存表
wa_db_item TYPE zmm_ap_po_item, "item缓存表结构
wa_if_item TYPE zpi_dt_oa_003_output_detail, "item同步接口结构
wa_if_head TYPE zpi_dt_oa_003_output_common. "head同步接口结构
DATA: wa_zmm_ap_po_head TYPE ty_zmm_ap_po_head, "手工同步选择的数据
wa_zmm_ap_po_item TYPE ty_zmm_ap_po_item.
FIELD-SYMBOLS: <fs_head> TYPE zpi_dt_oa_003_output_common,
<fs_zmm_ap_po_head> TYPE ty_zmm_ap_po_head.
DATA: lo_proxy TYPE REF TO zpi_co_si_oa_003_outbound.
DATA: ls_return_msg TYPE zpi_dt_oa_003_input_data.
CASE 'X'.
WHEN p_sync. "后台
SELECT *
FROM zmm_ap_po_head
INTO CORRESPONDING FIELDS OF TABLE ls_output-mt_oa_003_output-common
WHERE zupmod = '1' "自动更新的
AND zupflg = 'X'. "带更新标识的数据
IF ls_output-mt_oa_003_output-common IS NOT INITIAL.
SELECT *
FROM zmm_ap_po_item
INTO TABLE lt_db_items
FOR ALL ENTRIES IN ls_output-mt_oa_003_output-common
WHERE ebeln = ls_output-mt_oa_003_output-common-ebeln.
ENDIF.
LOOP AT ls_output-mt_oa_003_output-common ASSIGNING <fs_head> .
LOOP AT lt_db_items INTO wa_db_item WHERE ebeln = <fs_head>-ebeln.
CLEAR wa_if_item.
MOVE-CORRESPONDING wa_db_item TO wa_if_item.
APPEND wa_if_item TO <fs_head>-detail.
ENDLOOP.
ENDLOOP.
WHEN p_send. "手工
LOOP AT gt_zmm_ap_po_head INTO wa_zmm_ap_po_head WHERE box = 'X'.
CLEAR: wa_if_head.
MOVE-CORRESPONDING wa_zmm_ap_po_head TO wa_if_head.
LOOP AT gt_zmm_ap_po_item INTO wa_zmm_ap_po_item WHERE box = 'X' AND ebeln = wa_zmm_ap_po_head-ebeln.
CLEAR: wa_if_item.
MOVE-CORRESPONDING wa_zmm_ap_po_item TO wa_if_item.
APPEND wa_if_item TO wa_if_head-detail.
ENDLOOP.
APPEND wa_if_head TO ls_output-mt_oa_003_output-common.
ENDLOOP.
ENDCASE.
"Create object
lo_javascript = cl_java_script=>create( ).
"Compiler
CONCATENATE
`var lv_date = new Date().getTime();`
`lv_date;`
INTO l_javascript_code SEPARATED BY cl_abap_char_utilities=>cr_lf.
lo_javascript->compile( script_name = 'get_date.js' script = l_javascript_code ).
"Execute
ls_output-mt_oa_003_output-ts = lo_javascript->execute( 'get_date.js' ).
IF ls_output-mt_oa_003_output-ts IS INITIAL.
MESSAGE '获取时间戳错误,请稍后重试!' TYPE 'E'.
ENDIF.
l_string = lc_appid && ls_output-mt_oa_003_output-ts.
CALL FUNCTION 'MD5_CALCULATE_HASH_FOR_CHAR'
EXPORTING
data = l_string
* LENGTH = 0
* VERSION = 1
IMPORTING
hash = ls_hash
* TABLES
* DATA_TAB = DATA_TAB
EXCEPTIONS
no_data = 1
internal_error = 2
OTHERS = 3.
ls_output-mt_oa_003_output-key = ls_hash.
IF ls_output-mt_oa_003_output-key IS INITIAL.
MESSAGE '获取AppKey,请稍后重试!' TYPE 'E'.
ENDIF.
IF ls_output-mt_oa_003_output-common IS NOT INITIAL. "有数据,进行同步
IF lo_proxy IS INITIAL.
CREATE OBJECT lo_proxy.
ENDIF.
TRY.
CALL METHOD lo_proxy->si_oa_003_outbound
EXPORTING
output = ls_output
IMPORTING
input = ls_input.
CATCH cx_ai_system_fault .
CATCH cx_ai_application_fault .
ENDTRY.
SORT ls_input-mt_oa_003_input-common-data BY ebeln ASCENDING.
IF ls_input-mt_oa_003_input-common IS NOT INITIAL. "同步成功
LOOP AT ls_output-mt_oa_003_output-common ASSIGNING <fs_head>.
CLEAR: wa_db_head.
MOVE-CORRESPONDING <fs_head> TO wa_db_head.
wa_db_head-zcdate = sy-datum.
wa_db_head-zctime = sy-uzeit.
READ TABLE ls_input-mt_oa_003_input-common-data INTO ls_return_msg WITH KEY ebeln = <fs_head>-ebeln BINARY SEARCH.
IF sy-subrc = 0.
wa_db_head-type = ls_return_msg-type.
wa_db_head-message = ls_return_msg-message.
IF p_send = 'X'.
READ TABLE gt_zmm_ap_po_head ASSIGNING <fs_zmm_ap_po_head> WITH KEY ebeln = <fs_head>-ebeln BINARY SEARCH. "消息回写alv
IF sy-subrc = 0.
<fs_zmm_ap_po_head>-zcdate = sy-datum.
<fs_zmm_ap_po_head>-zctime = sy-uzeit.
<fs_zmm_ap_po_head>-type = ls_return_msg-type.
<fs_zmm_ap_po_head>-message = ls_return_msg-message.
CLEAR: <fs_zmm_ap_po_head>-zupflg. "取消同步标识
ENDIF.
ENDIF.
ENDIF.
CASE 'X'.
WHEN p_sync. "后台.
wa_db_head-zupmod = '1'. "自动更新
WHEN p_send.
wa_db_head-zupmod = '2'. "手动更新
WHEN OTHERS.
ENDCASE.
IF wa_db_head-type = 'S'.
CLEAR: wa_db_head-zupflg. "重置传输标识
ENDIF.
APPEND wa_db_head TO lt_db_head.
ENDLOOP.
MODIFY zmm_ap_po_head FROM TABLE lt_db_head. "回写本次同步返回的消息
ENDIF.
l_string = lines( ls_input-mt_oa_003_input-common-data ).
l_string = '本次同步:' && l_string && '条数据!'.
MESSAGE l_string TYPE 'S'.
ELSE.
MESSAGE '无数据更新' TYPE 'S'.
ENDIF.
ENDFORM. " FRM_SYNCDATA_OA