METHOD zyc_ii_si_data_dump_in~si_data_dump_in.
"反馈
DATA: output_hd TYPE zmmi005_dt_mesg_hd,
output_body TYPE zun_dt_un_resp_msgbd_tab,
output_line TYPE zun_dt_un_resp_msgbd.
DATA: r_obj TYPE REF TO zun_co_si_un_resp_out,
out TYPE zun_mt_un_resp.
*
TYPES: BEGIN OF emp,
fylhv TYPE resb-rsnum,
message_v1 TYPE string,
message_v2 TYPE string,
END OF emp.
DATA: l_itemid TYPE string,
l_msgid TYPE string.
TYPES : BEGIN OF st_ylfz,
usnam TYPE zsbbjjh-usnam,
werks TYPE zsbbjjh-werks,
bwart TYPE zsbbjjh-bwart,
bdter TYPE zsbbjjh-bdter,
kostl TYPE zsbbjjh-kostl,
aufnr TYPE zsbbjjh-aufnr,
wempf TYPE zsbbjjh-wempf,
umwrk TYPE zsbbjjh-umwrk,
umlgo TYPE zsbbjjh-umlgo,
anln1 TYPE zsbbjjh-anln1,
ekgrp TYPE zsbbjjh-ekgrp,
rsnum TYPE zsbbjjh-rsnum,
itemid TYPE zsbbjjh-itemid,
msgid TYPE zsbbjjh-msgid,
END OF st_ylfz.
DATA : reservation_header TYPE bapirkpfc,
lw_reservation TYPE bapiresbc,
reservation_items TYPE TABLE OF bapiresbc.
-
return TYPE TABLE OF bapireturn,
-
lw_return TYPE bapireturn,
-
lreturn TYPE TABLE OF bapireturn,
-
lw_lreturn TYPE bapireturn.
DATA : itab TYPE TABLE OF emp,
wa_1 TYPE emp.
DATA: tab1 TYPE TABLE OF st_ylfz,
tab_err TYPE TABLE OF st_ylfz,
tab_zylsp TYPE TABLE OF zsbbjjh. -
it_disp TYPE TABLE OF zsbbjjh WITH HEADER LINE.
DATA: wa_tab1 TYPE st_ylfz,
wa_zylsp TYPE zsbbjjh.
DATA: vylh TYPE resb-rsnum,
vanswer TYPE c,
v_continue TYPE c,
v_line TYPE i,
vindex TYPE sy-tabix.DATA: indx TYPE sy-tabix,
num_temp TYPE zsbbjjh_h-rspos.DATA: s_matnr TYPE RANGE OF zsbbjjh_h-matnr,
lw_matnr LIKE LINE OF s_matnr,s_budat TYPE RANGE OF zsbbjjh_h-budat, lw_budat LIKE LINE OF s_budat.
DATA : s_werks TYPE RANGE OF ekpo-werks,
lw_werks LIKE LINE OF s_werks.DATA: flag TYPE c,
l_con TYPE c."申请
TYPES : BEGIN OF ty_rsnum ,
rsnum TYPE zsbbjjh-rsnum,
END OF ty_rsnum.DATA: lt_rsnum TYPE TABLE OF ty_rsnum,
lw_rsnum TYPE ty_rsnum.DATA : lt_pr TYPE TABLE OF zsbbjjh_h,
lw_pr TYPE zsbbjjh_h,lt_temp TYPE TABLE OF zsbbjjh_h, lw_temp TYPE zsbbjjh_h, lt_modi TYPE TABLE OF zsbbjjh_h, lw_modi TYPE zsbbjjh_h.
DATA : requisition_items TYPE TABLE OF bapiebanc,
lw_req_items TYPE bapiebanc,return2 TYPE TABLE OF bapireturn, lw_return2 TYPE bapireturn, number TYPE bapiebanc-preq_no.
DATA : l_zcsj TYPE zsbbjjh-budat,
l_trac TYPE c LENGTH 10,
l_rec TYPE n LENGTH 6.DATA : r_zcsj TYPE RANGE OF sy-datum,
lw_zcsj LIKE LINE OF r_zcsj.TYPES: BEGIN OF ty_remsg,
include TYPE bapireturn,
idmsg TYPE string,
itemmsg TYPE string.
TYPES: END OF ty_remsg.DATA: lreturn TYPE TABLE OF ty_remsg,
lw_lreturn TYPE ty_remsg.DATA: return TYPE TABLE OF bapireturn,
lw_return TYPE bapireturn."拆分itemid
DATA: t_item TYPE TABLE OF string,
l_item LIKE LINE OF t_item.DATA: cgsq_item TYPE string.
LOOP AT input-mt_data_dump-msgbd INTO DATA(ls_msgbd).
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING input = ls_msgbd-matnr IMPORTING output = ls_msgbd-matnr. IF ls_msgbd-matnr IS NOT INITIAL. lw_matnr-sign = 'I'. lw_matnr-option = 'EQ'. lw_matnr-low = ls_msgbd-matnr. APPEND lw_matnr TO s_matnr. CLEAR:lw_matnr. ENDIF. lw_budat-sign = 'I'. lw_budat-option = 'EQ'. lw_budat-low = ls_msgbd-budat. APPEND lw_budat TO s_budat. CLEAR:lw_budat. IF ls_msgbd-zfzt = 'R1'. flag = 'X'. ENDIF.
ENDLOOP.
lw_werks-sign = ‘I’.
lw_werks-option = ‘EQ’.
lw_werks-low = ‘2064’.APPEND lw_werks TO s_werks.
CLEAR:lw_werks.lw_werks-sign = ‘I’.
lw_werks-option = ‘EQ’.
lw_werks-low = ‘2063’.
APPEND lw_werks TO s_werks.
CLEAR:lw_werks.lw_werks-sign = ‘I’.
lw_werks-option = ‘EQ’.
lw_werks-low = ‘2071’.
APPEND lw_werks TO s_werks.
CLEAR:lw_werks.IF flag = ‘X’. "转储
SELECT DISTINCT usnam werks bwart bdter kostl aufnr wempf umwrk umlgo anln1 ekgrp FROM zsbbjjh INTO TABLE tab1 WHERE werks IN s_werks AND budat IN s_budat AND matnr IN s_matnr AND fspr3 <> '' AND fsjly = '' AND usnam = 'YC_MES' ."201903添加过滤统采 "fspr2-->fspr3 IF sy-subrc <> 0.
-
MESSAGE i001(00) WITH '没有可用数据或未审批!'. output_line-retid = 'E'. output_line-rettxt = '没有可用数据或未审批!'. APPEND output_line TO output_body. CLEAR output_line. ENDIF. IF output_body IS INITIAL.
*****取所有审批后的数据
SELECT * FROM zsbbjjh INTO TABLE tab_zylsp WHERE werks IN s_werks AND budat IN s_budat AND matnr IN s_matnr AND fspr3 <> ‘’ AND fsjly = ‘’."201903添加过滤统采 "fspr2–>fspr3
SORT tab_zylsp BY rspos.
LOOP AT tab1 INTO wa_tab1.
vindex = sy-tabix.
reservation_header-res_date = wa_tab1-bdter."需求日期
reservation_header-created_by = wa_tab1-usnam."用户名
reservation_header-move_type = wa_tab1-bwart."移动类型
reservation_header-cost_ctr = wa_tab1-kostl."成本中心
reservation_header-order_no = wa_tab1-aufnr."订单号
reservation_header-move_plant = wa_tab1-umwrk."发货工厂
reservation_header-move_stloc = wa_tab1-umlgo."发货库存地
reservation_header-plant = wa_tab1-werks."工厂
reservation_header-gr_rcpt = wa_tab1-wempf."接受方
reservation_header-asset_no = wa_tab1-anln1."资产号
***add fdel3 = ‘’
num_temp = 1.
LOOP AT tab_zylsp INTO wa_zylsp WHERE fdel1 = ‘’ AND fdel2 = ‘’ AND fdel3 = ‘’ AND werks = wa_tab1-werks
AND usnam = wa_tab1-usnam AND bwart = wa_tab1-bwart AND bdter = wa_tab1-bdter
AND aufnr = wa_tab1-aufnr AND wempf = wa_tab1-wempf AND umwrk = wa_tab1-umwrk
AND umlgo = wa_tab1-umlgo AND kostl = wa_tab1-kostl AND ekgrp = wa_tab1-ekgrp AND anln1 = wa_tab1-anln1.
indx = sy-tabix.
lw_reservation-material = wa_zylsp-matnr."物料号
lw_reservation-plant = wa_zylsp-werks."工厂
lw_reservation-quantity = wa_zylsp-fsl3v."数量 fsl2v--> fsl3v
lw_reservation-req_date = wa_zylsp-bdter."日期
lw_reservation-gr_rcpt = wa_zylsp-wempf."收货方
lw_reservation-short_text = wa_zylsp-sgtxt."文本1
lw_reservation-movement = 'X'. "允许移动标志
APPEND lw_reservation TO reservation_items .
*****2019.7.19 添加预留的行号码信息
wa_zylsp-rspos1 = num_temp.
MODIFY tab_zylsp INDEX indx FROM wa_zylsp TRANSPORTING rspos1.
num_temp = num_temp + 1.
CLEAR: lw_reservation.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
input = wa_zylsp-matnr
IMPORTING
output = wa_zylsp-matnr.
IF l_msgid IS NOT INITIAL.
l_msgid = l_msgid && ',' && wa_zylsp-msgid && ':' && wa_zylsp-itemid .
ELSE.
l_msgid = wa_zylsp-msgid && ':' && wa_zylsp-itemid.
ENDIF.
IF l_itemid IS NOT INITIAL.
l_itemid = l_itemid && ',' && wa_zylsp-itemid.
ELSE.
l_itemid = wa_zylsp-itemid.
ENDIF.
CLEAR:wa_zylsp.
ENDLOOP.
*****如果没有项目数据则继续下一预留分组
IF reservation_items IS INITIAL.
CLEAR: reservation_header, lw_reservation,reservation_items[],return.
CONTINUE.
ENDIF.
CALL FUNCTION 'BAPI_RESERVATION_CREATE'
EXPORTING
reservation_header = reservation_header
IMPORTING
reservation = vylh
TABLES
reservation_items = reservation_items
return = return.
IF vylh = 0.
*****生成预留错误时的处理
APPEND wa_tab1 TO tab_err.
READ TABLE return INTO lw_return INDEX 1.
-
lw_return-message_v1 = wa_tab1-usnam.
-
lw_return-message_v2 = wa_tab1-bwart.
-
lw_return-message_v1 = wa_tab1-kostl.
-
lw_return-message_v2 = l_mara. lw_lreturn-idmsg = l_msgid. lw_lreturn-itemmsg = l_itemid. lw_lreturn-include-message = lw_return-message. APPEND lw_lreturn TO lreturn. CLEAR:lw_lreturn. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. wa_tab1-rsnum = vylh.
-
wa_tab1-message_v1 = wa_tab1-kostl.
-
wa_tab1-message_v2 = wa_tab1-bwart. SHIFT vylh LEFT DELETING LEADING '0'. wa_1-fylhv = vylh. wa_1-message_v1 = l_msgid. wa_1-message_v2 = l_itemid. APPEND wa_1 TO itab. MODIFY tab1 FROM wa_tab1 INDEX vindex. CLEAR:wa_1. ENDIF. CLEAR: reservation_header, reservation_items,reservation_items[],return,wa_1,l_itemid,l_msgid. ENDLOOP.
*****把生成的预留号填写到内表,为转到历史库做准备
*****生成预留号错误的不转储
LOOP AT tab_err INTO wa_tab1.
DELETE tab_zylsp WHERE werks = wa_tab1-werks AND usnam = wa_tab1-usnam AND bwart = wa_tab1-bwart
AND bdter = wa_tab1-bdter AND aufnr = wa_tab1-aufnr AND wempf = wa_tab1-wempf
AND umwrk = wa_tab1-umwrk AND umlgo = wa_tab1-umlgo AND kostl = wa_tab1-kostl
AND ekgrp = wa_tab1-ekgrp AND anln1 = wa_tab1-anln1.
ENDLOOP.
*****生成预留号 或分组为空的进行转储
LOOP AT tab1 INTO wa_tab1.
LOOP AT tab_zylsp INTO wa_zylsp WHERE usnam = wa_tab1-usnam AND werks = wa_tab1-werks AND bwart = wa_tab1-bwart
AND bdter = wa_tab1-bdter AND kostl = wa_tab1-kostl AND aufnr = wa_tab1-aufnr
AND wempf = wa_tab1-wempf AND umwrk = wa_tab1-umwrk AND umlgo = wa_tab1-umlgo
AND ekgrp = wa_tab1-ekgrp AND anln1 = wa_tab1-anln1.
vindex = sy-tabix.
wa_zylsp-fzcsj = sy-datum.
wa_zylsp-date_new = sy-datum.
wa_zylsp-flag_dl = ‘U’.
wa_zylsp-fzcrv = ‘YC_MES’.
IF wa_tab1-rsnum <> ‘’.
IF wa_zylsp-fdel1 = ‘’ AND wa_zylsp-fdel2 = ‘’ AND wa_zylsp-fdel3 = ‘’. "add wa_zylsp-fdel3 = ‘’
wa_zylsp-rsnum = wa_tab1-rsnum.
ENDIF.
ENDIF.
MODIFY tab_zylsp FROM wa_zylsp.
ENDLOOP.
ENDLOOP.
*****转到历史库并从当前表中删除
-
为保障两条修改数据库表语句的事务一致性 改成以下 start 20210901 by renyl
MODIFY zsbbjjh_h FROM TABLE tab_zylsp.
IF sy-subrc = 0.
DELETE zsbbjjh FROM TABLE tab_zylsp.
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDIF.
*end 20210901
****输出转储结果 -
DATA: yu TYPE i.
-
WRITE :/ '生成的预留号如下(详细内容见''计划查询''):',/ . LOOP AT itab INTO wa_1 WHERE fylhv <> 0.
-
output_line-itemid = sy-tabix. output_line-order1 = wa_1-fylhv. output_line-retid = 'S'.
-
output_line-rettxt = '没有可用数据或未审批!'. output_line-yl-yl1 = wa_1-message_v1. SPLIT wa_1-message_v2 AT ',' INTO TABLE t_item. LOOP AT t_item INTO l_item. output_line-yl-yl2 = l_item. APPEND output_line TO output_body. CLEAR: l_item. ENDLOOP.
-
output_line-yl-yl2 = wa_1-message_v2. CLEAR: output_line,t_item. ENDLOOP. LOOP AT lreturn INTO lw_lreturn.
-
output_line-itemid = sy-tabix. output_line-order1 = ''. output_line-retid = 'E'. output_line-rettxt = lw_lreturn-include-message . output_line-yl-yl1 = lw_lreturn-idmsg. SPLIT lw_lreturn-itemmsg AT ',' INTO TABLE t_item. LOOP AT t_item INTO l_item. output_line-yl-yl2 = l_item. APPEND output_line TO output_body. CLEAR: l_item. ENDLOOP.
-
output_line-yl-yl2 = lw_lreturn-itemmsg. CLEAR: output_line,t_item. ENDLOOP. ELSE."没有数据直接反馈 ENDIF. "反馈头信息 out-mt_un_resp-msghd-msgid = input-mt_data_dump-msghd-msgid. out-mt_un_resp-msghd-tlgid = input-mt_data_dump-msghd-tlgid. out-mt_un_resp-msghd-tlgname = input-mt_data_dump-msghd-tlgname. out-mt_un_resp-msghd-dtsend = sy-datum && sy-uzeit. out-mt_un_resp-msghd-sender = 'ERP'. out-mt_un_resp-msghd-receiver = input-mt_data_dump-msghd-sender. "反馈行信息 out-mt_un_resp-msgbd = output_body. TRY . CREATE OBJECT r_obj. CALL METHOD r_obj->si_un_resp_out EXPORTING output = out. COMMIT WORK AND WAIT. CALL FUNCTION 'ZFUN_PO_LOG' EXPORTING output1 = out. CATCH cx_ai_system_fault. ENDTRY.
ELSE."申请
lw_zcsj-sign = 'I'. lw_zcsj-option = 'BT'. lw_zcsj-low = sy-datum - 60. lw_zcsj-high = sy-datum. APPEND lw_zcsj TO r_zcsj. SELECT DISTINCT rsnum INTO TABLE lt_rsnum FROM zsbbjjh_h WHERE werks IN s_werks AND fzcsj IN r_zcsj AND banfn = '' AND fsjly = '' AND usnam = 'YC_MES'."201903添加过滤统采 DELETE lt_rsnum WHERE rsnum = ''. IF NOT lt_rsnum[] IS INITIAL. SELECT * INTO TABLE lt_pr FROM zsbbjjh_h FOR ALL ENTRIES IN lt_rsnum WHERE rsnum = lt_rsnum-rsnum AND fsjly = ''."201903添加过滤统采
-
WRITE : / '生成的采购请求如下(详细内容见''计划查询''):',/.
-
ULINE (110). SORT lt_pr BY rsnum rspos. LOOP AT lt_rsnum INTO lw_rsnum. l_rec = sy-tabix. REFRESH : requisition_items,return2,lt_temp. CLEAR number. LOOP AT lt_pr INTO lw_pr WHERE rsnum = lw_rsnum-rsnum. APPEND lw_pr TO lt_temp. "增加数据到临时表 lw_req_items-doc_type = 'NB'. "申请类型 lw_req_items-pur_group = lw_pr-ekgrp. "采购组 lw_req_items-preq_date = lw_pr-bdter. "需求日期 lw_req_items-material = lw_pr-matnr. "物料号 lw_req_items-plant = lw_pr-werks. "工厂 CASE lw_pr-bwart. WHEN '201'. l_trac = lw_pr-kostl. WHEN 'Z21'. l_trac = lw_pr-kostl. WHEN '301'. CONCATENATE lw_pr-umwrk ',' lw_pr-umlgo INTO l_trac. WHEN '241'. l_trac = lw_pr-anln1+2(10). WHEN '251'. l_trac = lw_pr-wempf. WHEN 'Z51'. l_trac = lw_pr-wempf. WHEN 'Y51'. l_trac = lw_pr-wempf. WHEN '261'. l_trac = lw_pr-aufnr+2(10). ENDCASE.
-
lw_req_items-store_loc = ''. "库存地 lw_req_items-trackingno = l_trac. "需求跟踪号 lw_req_items-preq_name = lw_pr-usnam. "用户名 lw_req_items-quantity = lw_pr-fsl3v. "数量 " fsl2v --> fsl3v lw_req_items-deliv_date = lw_pr-bdter. "交货期
*{ INSERT APEK901352 1
IF lw_pr-verpr IS INITIAL. "增加价格判断。20210624
lw_req_items-c_amt_bapi = lw_pr-fsgjg.
ELSE.
lw_req_items-c_amt_bapi = lw_pr-verpr.
ENDIF.
*} INSERT
APPEND lw_req_items TO requisition_items.
"记录所有itemid “R1和R2返回的vbillcode都需要修改成返回ITEMID的值” 申请号都不用嗯宋梦尧20230703
IF cgsq_item IS INITIAL.
cgsq_item = lw_pr-itemid.
ELSE.
cgsq_item = cgsq_item && ',' && lw_pr-itemid.
ENDIF.
CLEAR:lw_pr.
ENDLOOP.
CALL FUNCTION 'BAPI_REQUISITION_CREATE'
IMPORTING
number = number
TABLES
requisition_items = requisition_items
return = return2.
COMMIT WORK AND WAIT.
-
WRITE :/ '序号:',l_rec,'、预留号:',lw_pr-rsnum,'->','采购申请号:',number. IF number IS INITIAL. LOOP AT return2 INTO lw_return2. output_line-order1 = number. output_line-retid = 'E'. output_line-yl-yl1 = lw_rsnum-rsnum. output_line-rettxt = lw_return2-message && lw_return2-message_v1 && lw_return2-message_v2. SPLIT cgsq_item AT ',' INTO TABLE t_item. LOOP AT t_item INTO l_item. output_line-yl-yl2 = l_item. APPEND output_line TO output_body. CLEAR: l_item. ENDLOOP.
-
output_line-yl-yl2 = cgsq_item. CLEAR: output_line,t_item. ENDLOOP. ELSE. LOOP AT lt_temp INTO lw_temp. lw_temp-banfn = number. lw_temp-bnfpo = sy-tabix * 10. " MODIFY lt_temp FROM lw_temp. ENDLOOP. APPEND LINES OF lt_temp TO lt_modi. REFRESH lt_temp.
-
output_line-yl-yl2 = cgsq_item. output_line-yl-yl1 = lw_rsnum-rsnum. output_line-order1 = number. output_line-retid = 'S'.
-
output_line-yl-yl3 = lw_rsnum-rsnum.
-
output_line-rettxt = lw_return2-message && w_return2-message_v1 && lw_return2-message_v2. SPLIT cgsq_item AT ',' INTO TABLE t_item. LOOP AT t_item INTO l_item. output_line-yl-yl2 = l_item. READ TABLE lt_modi INTO DATA(l_modi) WITH KEY itemid = l_item. IF sy-subrc = 0. output_line-yl-yl3 = l_modi-bnfpo. ENDIF. APPEND output_line TO output_body. CLEAR: l_item,l_modi. ENDLOOP. CLEAR: output_line,t_item. ENDIF. CLEAR:lw_rsnum,cgsq_item. ENDLOOP. IF NOT lt_modi[] IS INITIAL. MODIFY zsbbjjh_h FROM TABLE lt_modi. ENDIF. ELSE.
-
MESSAGE '没有可以生成采购申请的数据!' TYPE 'I'.
-
output_line-tlgid = lw_pr-rsnum.
-
output_line-order1 = number. output_line-retid = 'E'. output_line-rettxt = '没有可以生成采购申请的数据'. APPEND output_line TO output_body. CLEAR output_line. ENDIF. "反馈头信息 out-mt_un_resp-msghd-msgid = input-mt_data_dump-msghd-msgid. out-mt_un_resp-msghd-tlgid = input-mt_data_dump-msghd-tlgid. out-mt_un_resp-msghd-tlgname = input-mt_data_dump-msghd-tlgname. out-mt_un_resp-msghd-dtsend = sy-datum && sy-uzeit. out-mt_un_resp-msghd-sender = 'ERP'. out-mt_un_resp-msghd-receiver = input-mt_data_dump-msghd-sender. "反馈行信息 out-mt_un_resp-msgbd = output_body. TRY . CREATE OBJECT r_obj. CALL METHOD r_obj->si_un_resp_out EXPORTING output = out. COMMIT WORK AND WAIT. CALL FUNCTION 'ZFUN_PO_LOG' EXPORTING output1 = out
-
output2 = out . CATCH cx_ai_system_fault. ENDTRY. " 备份,防止yc影响业务. DATA:ls_zmm_r2log TYPE zmm_r2log . IF out IS NOT INITIAL. MOVE-CORRESPONDING out-mt_un_resp-msghd TO ls_zmm_r2log. LOOP AT out-mt_un_resp-msgbd INTO DATA(line2). ls_zmm_r2log-itemid = line2-itemid . ls_zmm_r2log-order1 = line2-order1. ls_zmm_r2log-retid = line2-retid. ls_zmm_r2log-rettxt = line2-rettxt. ls_zmm_r2log-yl1 = line2-yl-yl1. ls_zmm_r2log-yl2 = line2-yl-yl2. ls_zmm_r2log-date1 = sy-datum. ls_zmm_r2log-time1 = sy-uzeit. MODIFY zmm_r2log FROM ls_zmm_r2log. ENDLOOP. COMMIT WORK. ENDIF.
ENDIF.
ENDMETHOD.