MIGO BAPI_GOODSMVT_CREATE创建及增强
1、MIGO过账BAPI新增字段
BAPI新增收货行号字段,保存外围系统的数据
1.1、MATDOC表新增收货行号
1.2、MSEG表新增收货行号
创建DDL视图用于扩展NSDM_E_MSEG
1.3、增强实施
BADI:MB_BAPI_GOODSMVT_CREATE
调用方法IF_EX_MB_BAPI_GOODSMVT_CREATE~EXTENSIONIN_TO_MATDOC
IMSEG结构中也要新增增强字段,用于传值
增强代码
"--------------------@斌将军--------------------
METHOD IF_EX_MB_BAPI_GOODSMVT_CREATE~EXTENSIONIN_TO_MATDOC. DATA: c_lenstruc TYPE i VALUE 30, wa_bapi_mb_header TYPE bapi_te_xmkpf, wa_bapi_mb_item TYPE bapi_te_xmseg, wa_extension_in TYPE bapiparex. FIELD-SYMBOLS: <fs_imseg> TYPE imseg. CHECK NOT extension_in[] IS INITIAL. * Analyze IMSEG for document structure and assign LINE_IDs if necessary CALL METHOD cl_mmim_line_id_manager=>analyze_mb_create CHANGING ct_imseg = ct_imseg[] EXCEPTIONS duplicate_line_id = 1 OTHERS = 2. LOOP AT extension_in INTO wa_extension_in. CASE wa_extension_in-structure. * extension of MKPF WHEN 'BAPI_TE_XMKPF'. MOVE wa_extension_in+c_lenstruc TO wa_bapi_mb_header. MOVE-CORRESPONDING wa_bapi_mb_header TO cs_imkpf. * extension of MSEG WHEN 'BAPI_TE_XMSEG'. MOVE wa_extension_in+c_lenstruc TO wa_bapi_mb_item. READ TABLE ct_imseg WITH KEY line_id = wa_bapi_mb_item-matdoc_itm ASSIGNING <fs_imseg>. IF sy-subrc EQ 0. MOVE-CORRESPONDING wa_bapi_mb_item TO <fs_imseg>. ENDIF. ENDCASE. ENDLOOP. ENDMETHOD.
"--------------------@斌将军--------------------
2、MIGO各情况代码示例
对应的gm_code取值:
* 01:采购订单的收货 * 02:生产订单的收货 * 03:发货 * 04:转移发布 * 05:其他收货 * 06:货物移动的逆转 * 07:关于转包订单的后续调整
当遇到移动类型不知道选择GOODSMVT_CODE对应的CODE时,可以通过移动类型查询T158B表和T158G,找到对应的CODE值
2.1、带增强字段的BAPI传值-移动类型531
"--------------------@斌将军-------------------- DATA:ls_imseg TYPE bapi_te_xmseg. DATA: ls_header TYPE bapi2017_gm_head_01, ls_mode TYPE bapi2017_gm_code, ls_goodsmvt_headret TYPE bapi2017_gm_head_ret, lt_goodsmvt_item TYPE STANDARD TABLE OF bapi2017_gm_item_create WITH HEADER LINE, * lt_goodsmvt_serialnumber TYPE STANDARD TABLE OF bapi2017_gm_serialnumber WITH HEADER LINE, lt_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE. DATA:lv_message TYPE char200, l_line_id TYPE mseg-line_id VALUE '000000', lv_check TYPE char1. * 01:采购订单的收货 * 02:生产订单的收货 * 03:发货 * 04:转移发布 * 05:其他收货 * 06:货物移动的逆转 * 07:关于转包订单的后续调整 ls_header-pr_uname = sy-uname. "用户名 ls_header-doc_date = '20220315'."gs_template1-bldat."LV_DATE. "凭证日期 ls_header-pstng_date = '20220315'."gs_template1-budat."LV_DATE. "过账日期 ls_header-header_txt = ''."gs_template1-id."LV_DATE. "抬头文本 ls_mode-gm_code = '05'. lt_goodsmvt_item-material = '000000000000210103'." lt_goodsmvt_item-plant = '2000'." lt_goodsmvt_item-stge_loc = '2021'."存储地点 lt_goodsmvt_item-move_type = '531'."移动类型 lt_goodsmvt_item-entry_qnt = '1'."以录入项单位表示的数量 lt_goodsmvt_item-entry_uom = 'KPC'."单位 lt_goodsmvt_item-orderid = '000100000349'."订单号 * 凭证行的唯一标识 l_line_id = l_line_id + 1. lt_goodsmvt_item-line_id = l_line_id. APPEND lt_goodsmvt_item.
CLEAR:ls_imseg. ls_imseg-matdoc_itm = l_line_id. ls_imseg-zline = lwa_pcsx-zline. CLEAR:ls_exte. ls_exte-structure = 'BAPI_TE_XMSEG'. ls_exte-valuepart1 = ls_imseg. APPEND ls_exte TO lt_exte. CALL FUNCTION 'BAPI_GOODSMVT_CREATE' EXPORTING goodsmvt_header = ls_header goodsmvt_code = ls_mode IMPORTING goodsmvt_headret = ls_goodsmvt_headret TABLES goodsmvt_item = lt_goodsmvt_item[] extensionin = lt_exte * goodsmvt_serialnumber = lt_goodsmvt_serialnumber[] return = lt_return. CLEAR:lv_message,lv_check. LOOP AT lt_return WHERE type CA 'EAX'. lv_check = 'E'. CONCATENATE lv_message lt_return-message INTO lv_message. CLEAR lt_return. ENDLOOP. "BAPI调用成功 IF lv_check = 'E'. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ENDIF. "--------------------@斌将军--------------------
2.2、采购退货-移动类型161
退货采购订单,执行101,生成161移动类型行项目
MIGO收货
代码要按照MIGO传值101移动类型,BAPI会自动产生161移动类型
"--------------------@斌将军--------------------
ls_mode-gm_code = '01'. CLEAR:ls_goodsmvt_item. ls_goodsmvt_item-po_number = '4100001418'."采购订单 ls_goodsmvt_item-po_item = '00010'."采购订单行项目 ls_goodsmvt_item-move_type = '101'."移动类型 ls_goodsmvt_item-mvt_ind = 'B'. "移动标识 ls_goodsmvt_item-material = '000000010000000002'."物料 ls_goodsmvt_item-plant = '1011'."工厂 ls_goodsmvt_item-stge_loc = '1001'."存储地点 ls_goodsmvt_item-entry_qnt = '1'."数量 ls_goodsmvt_item-entry_uom = 'EA'."单位 ls_goodsmvt_item-batch = 'A'."批次 APPEND ls_goodsmvt_item TO lt_goodsmvt_item.
"--------------------@斌将军--------------------
2.3、委外加工-移动类型543
委外加工,物料首层移动类型101,子层级移动类型543
MIGO收货
代码要按照MIGO传值101移动类型,并将子层级物料也作为行项目,且移动类型543,此处注意不要传入虚拟件的行
"--------------------@斌将军--------------------
ls_mode-gm_code = '01'. lv_line_id = lv_line_id + 1. CLEAR:ls_goodsmvt_item. ls_goodsmvt_item-line_id = lv_line_id."凭证行的唯一标识 0001 ls_goodsmvt_item-move_type = '101'."移动类型 ls_goodsmvt_item-mvt_ind = 'B'. "移动标识 ls_goodsmvt_item-po_number = '4600000020'."采购订单 ls_goodsmvt_item-po_item = '00010'."采购订单行项目 ls_goodsmvt_item-material = '000000010000000002'."物料 ls_goodsmvt_item-plant = '1011'."工厂 ls_goodsmvt_item-stge_loc = '1001'."存储地点 ls_goodsmvt_item-entry_qnt = '1'."数量 ls_goodsmvt_item-entry_uom = 'EA'."单位 ls_goodsmvt_item-batch = 'A'."批次 APPEND ls_goodsmvt_item TO lt_goodsmvt_item. CLEAR:ls_goodsmvt_item. ls_goodsmvt_item-parent_id = lv_line_id."父行标识 0001 lv_line_id = lv_line_id + 1. ls_goodsmvt_item-line_id = lv_line_id."凭证行的唯一标识 0002 ls_goodsmvt_item-move_type = '543'."移动类型 ls_goodsmvt_item-mvt_ind = 'O'. "移动标识 ls_goodsmvt_item-material = '000000010000000003'."物料 ls_goodsmvt_item-plant = '1011'."工厂 ls_goodsmvt_item-entry_qnt = '1'."数量 ls_goodsmvt_item-entry_uom = 'EA'."单位 ls_goodsmvt_item-batch = 'A'."批次 APPEND ls_goodsmvt_item TO lt_goodsmvt_item.
"--------------------@斌将军--------------------
2.4、传输过账-移动类型411/413/415
传输过账举例
前台如图
在BAPI传值时,注意转出和转入的参数,不要传反
"--------------------@斌将军--------------------
ls_mode-gm_code = '04'.
IF p_wa_upload-bwart = '413' AND p_wa_upload-sobkz = 'E'."销售订单到销售订单 ls_goodsmvt_item-val_sales_ord = p_wa_upload-vbeln."从销售订单 ls_goodsmvt_item-val_s_ord_item = p_wa_upload-posnr. ls_goodsmvt_item-sales_ord = p_wa_upload-d_vbeln."到销售订单 ls_goodsmvt_item-s_ord_item = p_wa_upload-d_posnr. ELSEIF p_wa_upload-bwart = '415' AND p_wa_upload-sobkz = 'Q'."项目转项目 ls_goodsmvt_item-val_wbs_elem = p_wa_upload-posid."从WBS ls_goodsmvt_item-wbs_elem = p_wa_upload-d_posid."到WBS ELSEIF p_wa_upload-bwart = '411' AND p_wa_upload-sobkz = 'E'."单转非限制 ls_goodsmvt_item-val_sales_ord = p_wa_upload-vbeln. ls_goodsmvt_item-val_s_ord_item = p_wa_upload-posnr. ELSEIF p_wa_upload-bwart = '411' AND p_wa_upload-sobkz = 'Q'."项目转非限制 ls_goodsmvt_item-val_wbs_elem = p_wa_upload-posid. ENDIF. "--------------------@斌将军--------------------
2.5、投料和退料
投料举例
参考代码
"--------------------@斌将军-------------------- DATA: ls_header TYPE bapi2017_gm_head_01, ls_mode TYPE bapi2017_gm_code, ls_goodsmvt_headret TYPE bapi2017_gm_head_ret, lt_goodsmvt_item TYPE STANDARD TABLE OF bapi2017_gm_item_create WITH HEADER LINE, lt_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE. DATA:lv_message TYPE char200, l_line_id TYPE mseg-line_id, lv_check TYPE char1. * 01:采购订单的收货 * 02:生产订单的收货 * 03:发货 * 04:转移发布 * 05:其他收货 * 06:货物移动的逆转 * 07:关于转包订单的后续调整 ls_header-pr_uname = sy-uname. "用户名 ls_header-doc_date = sy-datum."gs_template1-bldat."LV_DATE. "凭证日期 ls_header-pstng_date = sy-datum."gs_template1-budat."LV_DATE. "过账日期 ls_header-header_txt = ''."gs_template1-id."LV_DATE. "抬头文本 ls_mode-gm_code = '03'. lt_goodsmvt_item-material = '000000000003000008'." lt_goodsmvt_item-plant = 'P010'."工厂 lt_goodsmvt_item-stge_loc = '9101'."存储地点 lt_goodsmvt_item-move_type = 'Z62'."移动类型 lt_goodsmvt_item-entry_qnt = '1'."以录入项单位表示的数量 lt_goodsmvt_item-orderid = '000001000019'."订单号 lt_goodsmvt_item-val_type = 'ZIZHI'."评估类型 * 凭证行的唯一标识 l_line_id = l_line_id + 1. lt_goodsmvt_item-line_id = l_line_id. APPEND lt_goodsmvt_item. CALL FUNCTION 'BAPI_GOODSMVT_CREATE' EXPORTING goodsmvt_header = ls_header goodsmvt_code = ls_mode IMPORTING goodsmvt_headret = ls_goodsmvt_headret TABLES goodsmvt_item = lt_goodsmvt_item[] * extensionin = lt_exte * goodsmvt_serialnumber = lt_goodsmvt_serialnumber[] return = lt_return. CLEAR:lv_message,lv_check. LOOP AT lt_return WHERE type CA 'EAX'. lv_check = 'E'. lv_message = lv_message && lt_return-message. ENDLOOP. "BAPI调用成功 IF lv_check = 'E'. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ENDIF. "--------------------@斌将军--------------------
定期更文,欢迎关注