项目背景:
Z009类型的采购订单,101收货入库时,不需要产生检验批。
1.一般来说设置是否产生检验批,是通过设置物料管控的
2.但是这里因为别的原因,不能按物料来改。
3.最初是把采购订单的'库存类型'改为非限制(参考下图),无法达到目的,放弃这种做法!然后是在MIGO入库时,设置增强,模拟上述配置,临时跳过 生成检验批的代码,结果取消收货的时候报错,这里还要继续弄增强,
后续还不知道有没有别的地方需要弄。所以放弃这种跳过生成检验批的做法。
4.在过账时,生成一个后台作业,后台作业自动过账检验批,结果占用了物料凭证,出现异常问题。
5.最终增强放在过账后,再异步调用过账检验批的程序。
最终方案:
一、增强点 LMIGOKD1
IF sy-tcode eq 'MIGO'. * BREAK IT0003. DATA: lv_qalsC TYPE c. READ TABLE LT_XMSEG INTO DATA(LS_XMSEG) INDEX 1. IF SY-subrc EQ 0 AND LS_XMSEG-BWART EQ '101'. SELECT COUNT(*) FROM EKKO WHERE EBELN EQ LS_XMSEG-EBELN AND BSART EQ 'Z009'. IF SY-SUBRC EQ 0. CALL FUNCTION 'Z_RFC_PLM_031' * starting new task 'T1' "IN UPDATE TASK EXPORTING p_mblnr = LS_XMSEG-mblnr p_mjahr = LS_XMSEG-mjahr. * SUBMIT zmmr096 WITH p_mblnr = LS_XMSEG-mblnr * WITH p_mjahr = LS_XMSEG-mjahr. ENDIF. ENDIF. * get PARAMETER ID 'ZQALSX' FIELD lv_qalsC. ENDIF.
另外写了个程序,通过物料凭证找到检验批,并自动过账到非限制库存,使用RFC来异步调用(因为ZMMR096中有commit,需用常规函数调用远程函数并使用In new task)
附上zmmr096的代码
ZMMR096
*&---------------------------------------------------------------------* *& Report ZMMR096 *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zmmr096. INCLUDE zmmr096_head. INCLUDE zmmr096_screen. INCLUDE zmmr096_form. *采购订单类型为 Z009时,产生的检验批,需自动过账到非限制库存 START-OF-SELECTION. * CHECK sy-batch IS NOT INITIAL. PERFORM frm_prueflos_get. "获取检验批 PERFORM frm_prueflos_post."检验批自动决策 PERFORM frm_prueflos_post2."检验批自动过账 END-OF-SELECTION.
zmmr096_head
*&---------------------------------------------------------------------* *& 包含 ZMMR096_HEAD *&---------------------------------------------------------------------* TYPES: BEGIN OF sy_output. INCLUDE STRUCTURE qals. TYPES: ztype TYPE c, message TYPE camsg, END OF sy_output. DATA: gt_output TYPE TABLE OF sy_output. DATA: lv_flagc TYPE c, lv_times TYPE sy-tabix. DATA: gt_bdcdata TYPE STANDARD TABLE OF bdcdata, gt_bdcmsg TYPE STANDARD TABLE OF bdcmsgcoll. DATA:bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
ZMMR096_SCREEN
*&---------------------------------------------------------------------* *& 包含 ZMMR096_SCREEN *&---------------------------------------------------------------------* SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME TITLE TEXT-001. PARAMETERS: p_mblnr TYPE qals-mblnr, p_mjahr TYPE qals-mjahr. *SELECT-OPTIONS: s_budat FOR bsid-budat, * s_bukrs FOR bsid-bukrs, * s_kunnr FOR bsid-kunnr MODIF ID m1, * s_lifnr FOR bsik-lifnr MODIF ID m2, * s_hkont FOR bsid-hkont MODIF ID m3. *PARAMETERS: r1 RADIOBUTTON GROUP g1 USER-COMMAND u1, * r2 RADIOBUTTON GROUP g1, * r3 RADIOBUTTON GROUP g1. *PARAMETERS: p_check1 AS CHECKBOX. *SELECTION-SCREEN BEGIN OF LINE. *PARAMETERS: p_txt1 TYPE char10 DEFAULT '逻辑说明:' MODIF ID m4. *SELECTION-SCREEN COMMENT (30) TEXT-101. *SELECTION-SCREEN END OF LINE. *SELECTION-SCREEN BEGIN OF LINE. *PARAMETERS: p_txt2 TYPE char5 DEFAULT '' MODIF ID m4. *SELECTION-SCREEN COMMENT (40) TEXT-102. *SELECTION-SCREEN END OF LINE. *SELECTION-SCREEN BEGIN OF LINE. *PARAMETERS: p_txt3 TYPE char5 DEFAULT '' MODIF ID m4. *SELECTION-SCREEN COMMENT (50) TEXT-103. *SELECTION-SCREEN END OF LINE. *SELECTION-SCREEN BEGIN OF LINE. *PARAMETERS: p_txt4 TYPE char5 DEFAULT '' MODIF ID m4. *SELECTION-SCREEN COMMENT (50) TEXT-104. *SELECTION-SCREEN END OF LINE. *PARAMETERS: p_text1 TYPE char50 DEFAULT '期初日期为查询日期的最小日期的上月底' MODIF ID m4, * p_text2 TYPE char50 DEFAULT '账龄是查询日期的最大日期与记账日期对比' MODIF ID m4. SELECTION-SCREEN: END OF BLOCK b01.
ZMMR096_FORM
*&---------------------------------------------------------------------* *& 包含 ZMMR096_FORM *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form FRM_PRUEFLOS_POST *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_prueflos_get . * WAIT UP TO 5 SECONDS. SELECT * INTO CORRESPONDING FIELDS OF TABLE @gt_output FROM qals WHERE mblnr EQ @p_mblnr AND mjahr EQ @p_mjahr. IF gt_output[] IS INITIAL. lv_flagc = 'X'. ELSE. lv_flagc = ''. WAIT UP TO 1 SECONDS. ENDIF. WHILE lv_flagc = 'X'. ADD 1 TO lv_times. WAIT UP TO 2 SECONDS. PERFORM frm_prueflos_get. IF lv_times GE 900."大于半小时的时候,退出循环,避免陷入死循环 lv_flagc = 'E'. EXIT. ENDIF. ENDWHILE. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_PRUEFLOS_POST *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_prueflos_post . DATA ud_data LIKE bapi2045ud. DATA:ud_return_data LIKE bapi2045ud_return, stock_data LIKE bapi2045d_il2, ls_return LIKE bapireturn1. DATA:n TYPE i, lv_flg TYPE c, lv_anzfehler TYPE string. LOOP AT gt_output INTO DATA(ls_output). n = n + 1. * gs_out-prueflos = ls_output-prueflos. ud_data-insplot = ls_output-prueflos. "检验批 ud_data-ud_code = 'AC01'. "决策代码 ud_data-ud_plant = ls_output-werk. * ud_data-ud_recorded_by_user = sy-uname."ls_output-qvname. ud_data-ud_recorded_on_date = sy-datum. ud_data-ud_recorded_at_time = sy-uzeit. ud_data-ud_force_completion = 'X'. ud_data-ud_code_group = '1000'."<fs_decision>-vcodegrp. ud_data-ud_selected_set = '1000'."<fs_decision>-vauswahlmg. * ud_data-ud_stock_posting = 'X'. "是否进行过帐 CALL FUNCTION 'BAPI_INSPLOT_SETUSAGEDECISION' EXPORTING number = ls_output-prueflos ud_data = ud_data * LANGUAGE = IMPORTING ud_return_data = ud_return_data stock_data = stock_data return = ls_return. IF ls_return-type CA 'AEX'. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ls_output-ztype = 'E'. ls_output-message = '处理使用决策失败:' && ls_return-message. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ls_output-ztype = 'S'. ls_output-message = ls_return-message. ENDIF. MODIFY gt_output FROM ls_output. CLEAR ls_output. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_PRUEFLOS_POST2 *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_prueflos_post2 . DATA: json_ser TYPE REF TO cl_trex_json_serializer, json_des TYPE REF TO cl_trex_json_deserializer. DATA: jsonstr TYPE string. DATA: lt_zrfc_logs TYPE TABLE OF zrfc_logs, ls_zrfc_logs TYPE zrfc_logs. DATA: ep_message TYPE camsg, lv_losmenge TYPE char17, p_mode TYPE c VALUE 'N'. LOOP AT gt_output INTO DATA(ls_output) WHERE ztype = 'S'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING 'SAPMQEVA' '0100' 'X' '' ''. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_CURSOR' 'QALS-PRUEFLOS'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_OKCODE' '/00'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'QALS-PRUEFLOS' ls_output-prueflos."检验批号 PERFORM f_build_bdcdata TABLES gt_bdcdata USING 'SAPMQEVA' '0200' 'X' '' ''. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_OKCODE' '=BB'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_SUBSCR' 'SAPMQEVA 1101UD_HEADER'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_SUBSCR' 'SAPLSEXM 0200BADI_SUBSCR_1101'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_SUBSCR' 'SAPMQEVA 0101SUB_UD_DATA'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_SUBSCR' 'SAPMQEVA 1103UD_DATA'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_SUBSCR' 'RQEVA-VCODE'. * PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'RQEVA-VCODE' 'AC01'. * PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'RQEVA-VCODEGRP' '1000'. * PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'RQEVA-QKENNZAHL' '100'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING 'SAPMQEVA' '0200' 'X' '' ''. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_OKCODE' '=BU'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_SUBSCR' 'SAPMQEVA 1101UD_HEADER'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_SUBSCR' 'SAPLSEXM 0200BADI_SUBSCR_1101'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_SUBSCR' 'SAPMQEVA 0102SUB_UD_DATA'. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'BDC_SUBSCR' 'RQEVA-QLGO_VM01'. lv_losmenge = ls_output-losmenge. PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'RQEVA-VMENGE01' lv_losmenge. * PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'RQEVA-QLGO_VM01' ls_output-lagortvorg. * PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'RQEVA-QLGO_VM04' ls_output-lagortvorg. * PERFORM f_build_bdcdata TABLES gt_bdcdata USING '' '' '' 'RQEVA-QLGO_VM06' ls_output-lagortvorg. CALL TRANSACTION 'QA12' USING gt_bdcdata MODE p_mode MESSAGES INTO gt_bdcmsg. IF sy-subrc EQ 0. CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING msgid = sy-msgid msgnr = sy-msgno msgv1 = sy-msgv1 msgv2 = sy-msgv2 msgv3 = sy-msgv3 msgv4 = sy-msgv4 IMPORTING message_text_output = ep_message. ls_output-ztype = 'S'. lv_flagc = 'S'. ls_output-message = ls_output-message && ';' && ep_message. ELSE. CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING msgid = sy-msgid msgnr = sy-msgno msgv1 = sy-msgv1 msgv2 = sy-msgv2 msgv3 = sy-msgv3 msgv4 = sy-msgv4 IMPORTING message_text_output = ep_message. ls_output-ztype = 'E'. lv_flagc = 'E'. ls_output-message = ls_output-message && ';' && ep_message. ENDIF. * READ TABLE gt_bdcmsg INTO DATA(ls_bdcmsg) WITH KEY msgtyp = 'E'. CLEAR: gt_bdcdata,gt_bdcmsg. MODIFY gt_output FROM ls_output. ENDLOOP. * CREATE OBJECT json_ser * EXPORTING * data = it_twewt[]. * CALL METHOD json_ser->serialize. * CALL METHOD json_ser->get_data * RECEIVING * rval = jsonstr. ls_zrfc_logs-funcname = 'ZMMR096'. ls_zrfc_logs-zsystem = 'JYP'. ls_zrfc_logs-uname = sy-uname. * ls_zrfc_logs-zname1 = p_name1. ls_zrfc_logs-erdat = sy-datum. ls_zrfc_logs-uzeit = sy-uzeit. ls_zrfc_logs-ep_type = lv_flagc. ls_zrfc_logs-ep_message = ep_message. * ls_zrfc_logs-jsonstr1 = jsonstr. MODIFY zrfc_logs FROM ls_zrfc_logs. ENDFORM. *------------------------------------------------------------------------ * *------------------------------------------------------------------------ FORM f_build_bdcdata TABLES ct_bdcdata USING uv_program uv_dynpro uv_dynbegin uv_fnam uv_fval. DATA: ls_bdcdata TYPE bdcdata. CLEAR: ls_bdcdata. ls_bdcdata-program = uv_program. ls_bdcdata-dynpro = uv_dynpro. ls_bdcdata-dynbegin = uv_dynbegin. ls_bdcdata-fnam = uv_fnam. ls_bdcdata-fval = uv_fval. APPEND ls_bdcdata TO ct_bdcdata. ENDFORM.
PS: ME21N建立采购订单
ME29N审批后,就可以在MIGO做101入库了