REPORT ZSDR015.
TYPE-POOLS: slis,icon. TABLES: mkpf,mseg,zmb_send_log. DATA: lv_count TYPE i. DATA: BEGIN OF it_data OCCURS 0, sel(1) TYPE c, icon(50) TYPE c, mblnr LIKE zmb_send_log-mblnr, mjahr LIKE zmb_send_log-mjahr, kunnr LIKE zmb_send_log-kunnr, bldat LIKE zmb_send_log-bldat, budat LIKE zmb_send_log-budat, create_date LIKE zmb_send_log-create_date, create_time LIKE zmb_send_log-create_time, usnam LIKE zmb_send_log-usnam, pos_bktxt LIKE zmb_send_log-pos_bktxt, pos_flag LIKE zmb_send_log-pos_flag, errornum LIKE zmb_send_log-errornum, errormsg LIKE zmb_send_log-errormsg, send_date LIKE zmb_send_log-send_date, send_time LIKE zmb_send_log-send_time, send_usnam LIKE zmb_send_log-send_usnam, tcode LIKE zmb_send_log-tcode, sendnum LIKE zmb_send_log-sendnum, send_begin_time LIKE zmb_send_log-send_begin_time, mbcount LIKE zmb_send_log-mbcount, maxnum LIKE zmb_send_log-maxnum, rflag LIKE zmb_send_log-rflag, pos_rflag LIKE zmb_send_log-pos_rflag, send_rdate LIKE zmb_send_log-send_rdate, send_rtime LIKE zmb_send_log-send_rtime, send_rusnam LIKE zmb_send_log-send_rusnam, origin LIKE zmb_send_log-origin, biztpcode LIKE zmb_send_log-biztpcode, biztptxt LIKE zmb_send_log-biztptxt, timediff LIKE zmb_send_log-send_time. DATA: END OF it_data. DATA: BEGIN OF lt_mseg OCCURS 0, MBLNR like mkpf-MBLNR, MJAHR like mkpf-MJAHR, BLDAT like mkpf-BLDAT, BUDAT like mkpf-BUDAT, CPUDT like mkpf-CPUDT, KUNNR like mseg-KUNNR, BWART like mseg-BWART, END OF lt_mseg.
INCLUDE ZSDR015TOP.
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001. SELECT-OPTIONS:s_mblnr FOR mkpf-mblnr no INTERVALS, s_mjahr FOR mkpf-mjahr no INTERVALS, s_kunnr FOR mseg-kunnr no INTERVALS, s_budat FOR mkpf-budat , s_bldat FOR mkpf-bldat , s_cpudt FOR mkpf-cpudt DEFAULT sy-datum TO sy-datum, s_USNAM FOR mkpf-USNAM, s_flag FOR zmb_send_log-pos_flag no INTERVALS no-EXTENSION. SELECTION-SCREEN END OF BLOCK blk1. SELECTION-SCREEN BEGIN OF BLOCK blkr3 WITH FRAME TITLE text-003. PARAMETERS:p_mx RADIOBUTTON GROUP a DEFAULT 'X', "明细 p_err RADIOBUTTON GROUP a, "只显示异常错误 p_mseg RADIOBUTTON GROUP a. SELECTION-SCREEN END OF BLOCK blkr3. START-OF-SELECTION. PERFORM FRM_GET_DATA. PERFORM FRM_SET_DATA. PERFORM frm_show_alv.
INCLUDE ZSDR015SCR.
FORM set_pf_status USING rt_extab TYPE slis_t_extab. SET PF-STATUS '1100'. SET TITLEBAR 'TITLE1' WITH lv_count. ENDFORM.
INCLUDE ZSDR015I01.
FORM user_command_alv USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. CASE r_ucomm. WHEN 'ZSEND'. PERFORM frm_sendmb. WHEN 'SHOWLIST'. READ TABLE it_data INDEX rs_selfield-tabindex. PERFORM frm_show_list. WHEN 'REF'. PERFORM FRM_GET_DATA. PERFORM FRM_SET_DATA. WHEN '&IC1'. READ TABLE it_data INDEX rs_selfield-tabindex. IF rs_selfield-fieldname = 'MBLNR' AND rs_selfield-value <> ''. SET PARAMETER ID 'MBN' FIELD it_data-mblnr. SET PARAMETER ID 'MJA' FIELD it_data-mjahr. CALL TRANSACTION 'MB03' AND SKIP FIRST SCREEN. ELSE. PERFORM frm_show_list. ENDIF. ENDCASE. " 刷新ALV报表 rs_selfield-row_stable = rs_selfield-tabindex. rs_selfield-refresh = 'X'. ENDFORM. "user_command_alv
INCLUDE ZSDR015F01.
FORM FRM_GET_DATA. clear it_data. REFRESH it_data. "如果勾选只显示异常,清空所有条件,只查询错误的 if p_err eq 'X'. clear: s_mblnr,s_mjahr,s_bldat,s_budat,s_cpudt,s_kunnr,s_flag. REFRESH: s_mblnr,s_mjahr,s_bldat,s_budat,s_cpudt,s_kunnr,s_flag. s_flag-sign = 'I'. s_flag-option = 'EQ'. s_flag-low = 'F'. APPEND s_flag. endif. if p_mseg eq 'X'. PERFORM FRM_GET_MSEG. else. PERFORM FRM_GET_LOG. endif. DESCRIBE TABLE it_data LINES lv_count. ENDFORM. FORM FRM_GET_LOG. SELECT mblnr mjahr kunnr bldat budat create_date create_time usnam pos_bktxt pos_flag errornum errormsg send_date send_time send_usnam tcode sendnum send_begin_time mbcount maxnum rflag pos_rflag send_rdate send_rtime send_rusnam origin biztpcode biztptxt FROM zmb_send_log INTO CORRESPONDING FIELDS OF TABLE it_data WHERE mblnr IN s_mblnr AND mjahr IN s_mjahr AND kunnr IN s_kunnr AND bldat IN s_bldat AND budat IN s_budat AND create_date IN s_cpudt AND pos_flag IN s_flag AND USNAM in s_USNAM. ENDFORM. FORM FRM_GET_MSEG. SELECT a~MBLNR a~MJAHR b~KUNNR a~BLDAT a~BUDAT a~CPUDT a~CPUTM a~USNAM b~BWART c~pos_flag c~errornum c~errormsg c~send_date c~send_time c~send_usnam c~tcode c~sendnum c~send_begin_time c~mbcount c~maxnum c~rflag c~pos_rflag c~send_rdate c~send_rtime c~send_rusnam c~origin c~biztpcode c~biztptxt from mkpf as a INNER JOIN mseg as b on a~MBLNR = b~MBLNR and a~MJAHR = b~MJAHR INNER JOIN ZT156T as t on b~BWART = t~BWART and b~GRUND = t~GRUND left join zmb_send_log as c on b~MBLNR = c~MBLNR and b~MJAHR = c~MJAHR and b~KUNNR = c~KUNNR INTO CORRESPONDING FIELDS OF TABLE it_data where a~MBLNR in s_mblnr and a~MJAHR in s_mjahr and b~kunnr in s_kunnr and a~BUDAT in s_budat and a~BLDAT in s_bldat and a~CPUDT in s_cpudt and a~USNAM in s_USNAM %_HINTS ORACLE '&SUBSTITUTE VALUES&'. SORT it_data BY MBLNR MJAHR KUNNR. delete ADJACENT DUPLICATES FROM it_data COMPARING MBLNR MJAHR KUNNR. ENDFORM. FORM FRM_SET_DATA. LOOP AT it_data. CASE it_data-pos_flag. WHEN 'T'. it_data-icon = icon_led_green. WHEN 'F'. it_data-icon = icon_led_red. WHEN 'S'. it_data-icon = icon_led_green. it_data-pos_flag = 'S'. WHEN OTHERS. it_data-icon = icon_led_red. it_data-pos_flag = 'F'. ENDCASE. it_data-timediff = it_data-send_rtime - it_data-send_begin_time. MODIFY it_data TRANSPORTING icon pos_flag timediff. ENDLOOP. ENDFORM. FORM frm_show_alv. DATA: wa_alv_field TYPE slis_fieldcat_alv, wa_alv_fieldcat TYPE slis_t_fieldcat_alv, wa_layout TYPE slis_layout_alv, i_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE. DEFINE add_field. wa_alv_field-fieldname = &1. wa_alv_field-reptext_ddic = &2. wa_alv_field-checkbox = &3. "可选 wa_alv_field-edit = &4. "是否 可编缉 wa_alv_field-outputlen = &5. "长度 wa_alv_field-do_sum = &6. wa_alv_field-just = &7. append wa_alv_field to wa_alv_fieldcat. clear wa_alv_field. END-OF-DEFINITION. CLEAR wa_layout. wa_layout-edit = ''. wa_layout-edit_mode = space. wa_layout-zebra = 'X'. wa_layout-colwidth_optimize = ''. wa_layout-box_fieldname = 'SEL'. CLEAR i_sort. i_sort-fieldname = 'MBLNR'. i_sort-spos = 1. i_sort-up = 'X'. i_sort-subtot = 'X'. APPEND i_sort. "add_field 'SEL' '选择' 'X' '' 4 ''. add_field 'ICON' '状态' '' '' 4 '' 'C'. add_field 'BIZTPCODE' '业务代码' '' '' 8 '' ''. add_field 'BIZTPTXT' '业务描述' '' '' 8 '' ''. add_field 'MBLNR' '商品凭证' '' '' 12 '' ''. add_field 'MJAHR' '凭证年度' '' '' 8 '' ''. add_field 'KUNNR' '门店编号' '' '' 8 '' ''. add_field 'BLDAT' '凭证日期' '' '' 12 '' ''. add_field 'BUDAT' '记帐日期' '' '' 12 '' ''. add_field 'CREATE_DATE' '输入日期' '' '' 12 '' ''. add_field 'CREATE_TIME' '输入时间' '' '' 10 '' ''. add_field 'MBCOUNT' '凭证项目数' '' '' 10 '' ''. add_field 'USNAM' '用户名' '' '' 10 '' ''. add_field 'POS_FLAG' '是否成功' '' '' 8 '' ''. add_field 'SEND_DATE' '首次下发日期' '' '' 12 '' ''. add_field 'SEND_TIME' '首次下发时间' '' '' 10 '' ''. add_field 'SEND_USNAM' '首次下发人' '' '' 10 '' ''. add_field 'SENDNUM' '发送次数' '' '' 8 '' ''. add_field 'TCODE' '事务码' '' '' 10 '' ''. add_field 'MAXNUM' '重发限制条数' '' '' 8 '' ''. add_field 'RFLAG' '是否需重发' '' '' 8 '' ''. " add_field 'POS_RFLAG' '重发是否成功' '' '' 10 '' ''. add_field 'SEND_RDATE' '重发日期' '' '' 10 '' ''. add_field 'SEND_RTIME' '重发时间' '' '' 10 '' ''. add_field 'SEND_RUSNAM' '重发人' '' '' 10 '' ''. add_field 'TIMEDIFF' '重发执行时间' '' '' 10 '' ''. add_field 'ERRORNUM' '失败次数' '' '' 8 '' ''. add_field 'ERRORMSG' '消息文本' '' '' 20 '' ''. add_field 'ORIGIN' '来源' '' '' 10 '' ''. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid it_fieldcat = wa_alv_fieldcat is_layout = wa_layout i_callback_pf_status_set = 'SET_PF_STATUS' i_callback_user_command = 'USER_COMMAND_ALV' i_save = 'A' it_sort = i_sort[] TABLES t_outtab = it_data EXCEPTIONS program_error = 1 OTHERS = 2. ENDFORM. "showalv FORM frm_process USING p_info. CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 100 text = p_info EXCEPTIONS OTHERS = 1. ENDFORM. "process FORM frm_sendmb. DATA: BEGIN OF t_mblnr OCCURS 0, mblnr LIKE mkpf-mblnr, mjahr LIKE mkpf-mjahr, END OF t_mblnr. DATA: p_answer TYPE flag, p_taskname(30) TYPE c, t_mkpf LIKE TABLE OF mkpf WITH HEADER LINE, t_mseg LIKE TABLE OF mseg WITH HEADER LINE, wa_mkpf_send TYPE mkpf, t_mseg_send LIKE TABLE OF mseg WITH HEADER LINE. "取选中的凭证号 LOOP AT it_data WHERE sel EQ 'X'. t_mblnr-mblnr = it_data-mblnr. t_mblnr-mjahr = it_data-mjahr. APPEND t_mblnr. ENDLOOP. SORT t_mblnr BY mblnr mjahr. DELETE ADJACENT DUPLICATES FROM t_mblnr COMPARING mblnr mjahr. IF t_mblnr[] IS INITIAL. MESSAGE '请最少选择一条行项目' TYPE 'S'. RETURN. ENDIF. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP ' EXPORTING textline1 = '是否确定要向POS发送选中的物料凭证?' titel = '系统提示' cancel_display = '' IMPORTING answer = p_answer. IF p_answer <> 'J'. RETURN. ENDIF. "取选中凭证的详细信息 IF t_mblnr[] IS NOT INITIAL. SELECT * FROM mkpf INTO TABLE t_mkpf FOR ALL ENTRIES IN t_mblnr WHERE mblnr = t_mblnr-mblnr AND mjahr = t_mblnr-mjahr. SORT t_mkpf BY mblnr mjahr. SELECT * FROM mseg INTO TABLE t_mseg FOR ALL ENTRIES IN t_mblnr WHERE mblnr = t_mblnr-mblnr AND mjahr = t_mblnr-mjahr. SORT t_mseg BY mblnr mjahr. ENDIF. "按凭证数循环发送 LOOP AT t_mblnr. CLEAR: wa_mkpf_send,t_mseg_send,t_mseg_send[],p_taskname. PERFORM frm_process USING '正在发送数据,请稍后......'. READ TABLE t_mkpf INTO wa_mkpf_send WITH KEY mblnr = t_mblnr-mblnr mjahr = t_mblnr-mjahr BINARY SEARCH. LOOP AT t_mseg WHERE mblnr = t_mblnr-mblnr AND mjahr = t_mblnr-mjahr. CLEAR t_mseg_send. MOVE-CORRESPONDING t_mseg TO t_mseg_send. APPEND t_mseg_send. ENDLOOP. CONCATENATE wa_mkpf_send-mblnr sy-datum sy-uzeit INTO p_taskname. "下发 CALL FUNCTION 'ZSD_POS_SENDMB' STARTING NEW TASK p_taskname EXPORTING IS_MKPF = wa_mkpf_send IV_TYPE = 'U' IV_MAXNUM = '9999' IV_TCODE = sy-tcode TABLES IT_MSEG = t_mseg_send. "COMMIT WORK. ENDLOOP. MESSAGE '下发完毕,请查看下发结果!' TYPE 'I'. ENDFORM. FORM frm_show_list. RANGES: s_mblnr_z FOR mkpf-mblnr, s_mjahr_z FOR mkpf-mjahr, s_kunnr_z FOR mseg-kunnr. s_mblnr_z-low = it_data-mblnr. APPEND s_mblnr_z. s_mjahr_z-low = it_data-mjahr. APPEND s_mjahr_z. s_kunnr_z-low = it_data-kunnr. APPEND s_kunnr_z. SUBMIT ZSDR016 WITH s_mblnr IN s_mblnr_z WITH s_mjahr IN s_mjahr_z WITH s_kunnr IN s_kunnr_z AND RETURN. ENDFORM.