DEMO-创建外向交货单BAPI_OUTB_DELIVERY_CREATE_SLS
SAP各模块常用的BAPI

SAP各模块常⽤的BAPI MM模块1、 BAPI_MATERIAL_SAVEDATA 创建物料主数据注意参数EXTENSIONIN的使⽤,可以创建⾃定义字段例如:WA_BAPI_TE_MARA-MATERIAL = ITAB_UP-MATNR.T_EXTENSIONIN-STRUCTURE = 'BAPI_TE_MARA'.T_EXTENSIONIN-VALUEPART1 = WA_BAPI_TE_MARA.APPEND T_EXTENSIONIN.WA_BAPI_TE_MARAX-MATERIAL = ITAB_UP-MATNR. T_EXTENSIONINX-STRUCTURE = 'BAPI_TE_MARAX'.T_EXTENSIONINX-VALUEPART1 = WA_BAPI_TE_MARAX.APPEND T_EXTENSIONINX.2、 BAPI_OBJCL_CREATE 分类视图的创建3、 BAPI_OBJCL_GETCLASSES 分类视图得到详细信息4、 BAPI_MATERIAL_SAVEREPLICA 物料视图的扩充5、 BAPI_GOODSMVT_CREATE 创建物料凭证注意表T158G可以决定goodsmvt_codeGOODSMVT_CODE参数对应值: 01 MB01 02 MB31 03 MB1A 04 MB1B 05 MB1C 06 MB11 07 MB046、 BAPI_GOODSMVT_CANCEL 冲销物料凭证7、 BAPI_PR_CREATE 创建PR8、 BAPI_PO_CREATE1 创建PO9、 BAPI_PO_CHANGE 修改PO和删除PO10、WS_REVERSE_GOODS_ISSUE 冲销交货单的过账发货11、BAPI_RESERVATION_CREATE1 创建预留如果要检查ATP,必须使⽤BAPI_RESERVATION_CREATE12、BAPI_RESERVATION_CHANGE 修改和删除预留13、PRICES_CHANGE PRICES_POST 更改物料移动平均价或者标准价格如果要检查ATP,必须使⽤第⼆个SD模块1、 BAPI_SALESORDER_CREATEFROMDAT2 创建销售订单2、 SD_SALESDOCUMENT_CREATE 创建销售订单3、 BAPI_OUTB_DELIVERY_CREATE_SLS 根据销售订单创建交货单4、 BAPI_BILLINGDOC_CREATEMULTIPLE 创建发票,注意参数ref_doc_ca5、 BAPI_SALESORDER_CHANGE 修改或者删除销售订单6、 MB_CANCEL_GOODS_MOVEMENT 冲销交货单的过账发货7、 BAPI_BILLINGDOC_CANCEL1 发票的冲销8、 BAPI_OUTB_DELIVERY_CHANGE 修改外向交货单9、 SD_DELIVERY_UPDATE_PICKING 修改外向交货单拣配数量10、WS_DELIVERY_UPDATE 外向交货单的发货过账11、SD_CUSTOMER_MAINTAIN_ALL 创建客户。
[BAPI]使用BAPI_GOODSMVT_CREATE创建委外订单(subcontrac。。。
![[BAPI]使用BAPI_GOODSMVT_CREATE创建委外订单(subcontrac。。。](https://img.taocdn.com/s3/m/5324cb14fe00bed5b9f3f90f76c66137ef064f5c.png)
[BAPI]使⽤BAPI_GOODSMVT_CREATE创建委外订单(subcontrac。
下⾯介绍⼀下使⽤bapi BAPI_GOODSMVT_CREATE为委外订单创建物料移动凭证。
例⼦代码:*&---------------------------------------------------------------------**& Report YTEST_SUBCONTRACT_MIGO*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT ytest_subcontract_migo.DATA:lt_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE,l_doc TYPE mseg-mblnr,l_year TYPE mseg-mjahr,lt_item TYPE STANDARD TABLE OF bapi2017_gm_item_create WITH HEADER LINE,lwa_header TYPE bapi2017_gm_head_01,lwa_code TYPE bapi2017_gm_code.DATA:l_line_id TYPE mseg-line_id VALUE '000000',l_parent_id TYPE mseg-parent_id VALUE '000000',l_line_depth TYPE mseg-line_depth VALUE '00'.lwa_code-gm_code = '01' . "MB01lwa_header-pstng_date = sy-datum. "凭证中的过帐⽇期lwa_header-doc_date = sy-datum. "凭证中的凭证⽇期lwa_header-pr_uname = sy-uname. "⽤户名lwa_header-ref_doc_no = '123456'. "参考订单lwa_header-header_txt = 'Header text'. "抬头⽂本* 物料lt_item-material = '000000410000000043'.* ⼯⼚lt_item-plant = '1286'.* 批次号lt_item-batch = '1808031000'.* 移动类型lt_item-move_type = '101'.* 库存地点lt_item-stge_loc = '1103'.* 基本单位数量lt_item-entry_qnt = 57040.* 输⼊单位lt_item-entry_uom = 'KG'.* 订单单位数量lt_item-po_pr_qnt = 57040.* 订单价格单位(采购)lt_item-orderpr_un = 'KG'.* 采购订单号lt_item-po_number = 4400000011.* 采购凭证的项⽬编号lt_item-po_item = '00010'.lt_item-mvt_ind = 'B'.* 凭证⾏的唯⼀标识l_line_id = l_line_id + 1.l_parent_id = l_line_id.lt_item-line_id = l_line_id.APPEND lt_item.CLEAR:lt_item.lt_item-move_type = '543'.* 物料编号lt_item-material = '000000410000000044'.* ⼯⼚lt_item-plant = '1286'.lt_item-spec_stock = 'O'.* 批次号lt_item-batch = '0000000004'.* 数量lt_item-entry_qnt = 3600.* 基本计量单位lt_item-entry_uom = 'KG'.* 上⼀⾏的识别码lt_item-parent_id = l_parent_id.* 凭证⾏的唯⼀标识l_line_id = l_line_id + 1.lt_item-line_id = l_line_id.* 凭证中⾏层次结构级别l_line_depth = '01'.lt_item-line_depth = l_line_depth.APPEND lt_item.CALL FUNCTION'BAPI_GOODSMVT_CREATE'EXPORTINGgoodsmvt_header = lwa_headergoodsmvt_code = lwa_code* TESTRUN = ' '* GOODSMVT_REF_EWM =* GOODSMVT_PRINT_CTRL =IMPORTING* GOODSMVT_HEADRET =materialdocument = l_docmatdocumentyear = l_yearTABLESgoodsmvt_item = lt_itemreturn = lt_return.LOOP AT lt_return WHERE type CA 'AEX'.EXIT.ENDLOOP.IF sy-subrc = 0.CALL FUNCTION'BAPI_TRANSACTION_ROLLBACK'.WRITE:'Failed'.ELSE.CALL FUNCTION'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.WRITE:'物料凭证号:', l_doc.ENDIF.代码不复杂,需要注意的是字段line_id,parent_id,line_depth要填写正确,line_id是⽤来唯⼀标识⾏项⽬的,委外⾏要正确制定上层⾏项⽬ID,也就是把上层⾏项⽬的line_ID填到委外⾏的parent_ID字段中,line_depth也要按层次填⼊01...如果⾏项⽬字段填写不正确有时会出现M7 387错误。
◆◆0[BAPI]外向交货单按批次拆分[BAPI_OUTB_DELIVERY_CHANGE]
![◆◆0[BAPI]外向交货单按批次拆分[BAPI_OUTB_DELIVERY_CHANGE]](https://img.taocdn.com/s3/m/f49e4a472a160b4e767f5acfa1c7aa00b52a9d9d.png)
◆◆0[BAPI]外向交货单按批次拆分[BAPI_OUTB_DELIVERY_CHANGE]三⽉ 20, 2017 9,583 views[隐藏]下⾯介绍SAP SD的销售订单外向交货单按批次拆分(Batch-Managed),包括前台操作和调⽤bapi ‘BAPI_OUTB_DELIVERY_CHANGE’ 实现。
1, 前台操作按批次拆分操作:外向交货单Tcode: VL02n选中10⾏项⽬,点击‘批次拆分’按钮,填写批次后,回车,会将项⽬号和库位⾃动带出(视具体配置⽽定)点保存后,原来航项⽬10数量⾃动变更,变成0.删除批次拆分操作:选中刚才创建的拆分项⽬90001和90002,点删除按钮。
10⾏项⽬数量会⾃动更新,重新变成32, BAPI实现完整代码:其中1LW_ITEM_DATA-USEHIERITM = '1'.查看了domain中的固定值:‘1’代表Batch Subitem1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25REPORT ztest_bapi_sobitch.PARAMETERS p_vbeln TYPE vbeln_vl DEFAULT '8000003765'."测试批次拆分DATA:lit_header_partner LIKE TABLE OF bapidlvpartnerchg , "交货:合作伙伴更改lit_header_deadlines LIKE TABLE OF bapidlvdeadln , "交货截⽌⽇期lit_item_data LIKE TABLE OF bapiobdlvitemchg , "更改外向交货拣配数据项⽬等级lit_item_control LIKE TABLE OF bapiobdlvitemctrlchg , "外向交货项⽬级别控制数据lit_ret LIKE TABLE OF bapiret2 WITH HEADER LINE , "返回参数lit_item_data_spl LIKE TABLE OF /spe/bapiobdlvitemchg , "更改向外交货拣配数据项⽬等级(SPE) is_header_data LIKE bapiobdlvhdrchg , "更改外向交货拣配数据表头等级is_header_control LIKE bapiobdlvhdrctrlchg , "外向交货标题级别控制数据iv_delivery LIKE bapiobdlvhdrchg-deliv_numb . "交货DATA:lwa_header_partner LIKE bapidlvpartnerchg , "交货:合作伙伴更改lwa_header_deadlines LIKE bapidlvdeadln , "交货截⽌⽇期lwa_item_data LIKE bapiobdlvitemchg , "更改外向交货拣配数据项⽬等级lwa_item_control LIKE bapiobdlvitemctrlchg , "外向交货项⽬级别控制数据lwa_return LIKE bapiret2 . "返回参数DATA: l_techn_control TYPE bapidlvcontrol.25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93DATA: l_techn_control TYPE bapidlvcontrol.DATA:ls_item TYPE bapiobdlvitemchg,ls_item_t TYPE bapiobdlvitemchg,ls_item_control TYPE bapiobdlvitemctrlchg,ls_deadlines TYPE bapidlvdeadln.iv_delivery = p_vbeln. "交货单号"头信息is_header_data-deliv_numb = p_vbeln. "交货单号is_header_control-deliv_numb = p_vbeln."修改原10⾏项⽬数量CLEAR lwa_item_data.lwa_item_data-deliv_numb = p_vbeln.lwa_item_data-deliv_item = 10. "原⾏项⽬lwa_item_data-dlv_qty = 1.lwa_item_data-dlv_qty_imunit = 1.lwa_item_data-base_uom = 'TO'. "基本单位lwa_item_data-sales_unit = 'TO'. "销售单位lwa_item_data-fact_unit_nom = 1. "销售数量转换成SKU的分⼦(因⼦) lwa_item_data-fact_unit_denom = 1. "销售数量转换为 SKU 的值(除数)APPEND lwa_item_data TO lit_item_data .CLEAR lwa_item_control.lwa_item_control-deliv_numb = p_vbeln.lwa_item_control-deliv_item = 10. "原⾏项⽬lwa_item_control-chg_delqty = 'X'. "数量修改标志APPEND lwa_item_control TO lit_item_control."新拆分的批次CLEAR lwa_item_data.lwa_item_data-deliv_numb = p_vbeln.lwa_item_data-deliv_item = '900001'. "拆分后的新⾏项⽬lwa_item_data-hieraritem = 10. "上级⾏项⽬lwa_item_data-batch = 'YS91480001'. "新批次lwa_item_data-dlv_qty = 1. "⾃⼰重新计算拆分后的数量,lwa_item_data-dlv_qty_imunit = 1.lwa_item_data-fact_unit_nom = 1. "销售数量转换成SKU的分⼦(因⼦) lwa_item_data-fact_unit_denom = 1. "销售数量转换为 SKU 的值(除数)lwa_item_data-base_uom = 'TO'. "基本单位lwa_item_data-sales_unit = 'TO'. "销售单位lwa_item_data-usehieritm = '1'.APPEND lwa_item_data TO lit_item_data.CLEAR lwa_item_data.lwa_item_data-deliv_numb = p_vbeln.lwa_item_data-deliv_item = '900002'. "拆分后的新⾏项⽬lwa_item_data-hieraritem = 10. "上级⾏项⽬lwa_item_data-batch = 'YS91480002'."新批次lwa_item_data-dlv_qty = 1.lwa_item_data-dlv_qty_imunit = 1.lwa_item_data-fact_unit_nom = 1. "销售数量转换成SKU的分⼦(因⼦) lwa_item_data-fact_unit_denom = 1. "销售数量转换为 SKU 的值(除数)lwa_item_data-base_uom = 'TO'. "基本单位lwa_item_data-sales_unit = 'TO'. "销售单位lwa_item_data-usehieritm = '1'.9394 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143APPEND lwa_item_data TO lit_item_data.CLEAR lwa_item_control.lwa_item_control-deliv_numb = p_vbeln.lwa_item_control-deliv_item = '900001'. "拆分后的新⾏项⽬lwa_item_control-chg_delqty = 'X'. "数量修改标志APPEND lwa_item_control TO lit_item_control . CLEAR lwa_item_control.lwa_item_control-deliv_numb = p_vbeln.lwa_item_control-deliv_item = '900002'."拆分后的新⾏项⽬lwa_item_control-chg_delqty = 'X'. "数量修改标志APPEND lwa_item_control TO lit_item_control .CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE' EXPORTINGheader_data = is_header_dataheader_control = is_header_controldelivery = iv_deliveryTABLESheader_partner = lit_header_partnerheader_deadlines = lit_header_deadlinesitem_data = lit_item_dataitem_control = lit_item_controlreturn = lit_ret* ITEM_DATA_SPL = IT_ITEM_DATA_SPL.DATA: l_msg TYPE string.IF lit_ret[] IS INITIAL.COMMIT WORK AND WAIT.WRITE:/ '批次拆分成功'.RETURN.ENDIF.LOOP AT lit_ret WHERE type = 'E'.CLEAR l_msg.MESSAGE ID lit_ret-idTYPE 'E'NUMBER lit_ret-numberWITH lit_ret-message_v1lit_ret-message_v2lit_ret-message_v3lit_ret-message_v4INTO l_msg.WRITE:/ l_msg.ENDLOOP.选择画⾯:3, 保存批次数据库表外向交货单批次的相关数据保存在表LIPS中,LIPS-UECHA:批次拆分项⽬的上层项⽬以上⾯的数据为例:LIKPLIPSVBFA: 销售凭证流以上。
SAPSD基础知识之创建并处理外向交货单

SAPSD基础知识之创建并处理外向交货单SAP SD基础知识之创建并处理外向交货单⼀,创建外向交货单的选项Options for Creating Outbound Deliveries我们可以⼿动地创建outbound delivery,参考或者不参考特定的销售订单,也可以参考公司代码间/公司代码内STO这样的特殊类型的采购订单去创建outbound delivery单据。
如果我们使⽤集中处理,我们可以为所有类型的shipping documents交货,在这种情况下,系统⾃动地创建若⼲的outbound deliveries,可以前台⼿动处理也可以后台作业的⽅式处理。
⼆,交货清单Delivery ListDelivery List是需要交货的所有交易的清单。
我们使⽤不同的标准选择凭证来集中处理delivery,下⼀步,系统⾃动创建outbound deliveries;如果shipping criteria相同,系统合并这些凭证到⼀张outbound delivery;反过来,系统分割⼀个交易到⼏张outbound deliveries。
我们可以⽤delivery scenarios来为不同的deliveries业务流程建模;当我们处理delivery list,我们仅需要选择⼀个scenario;三,交货场景 Delivery Scenarios⼀个delivery scenario模型化了为交付货物以满⾜不同的类型订单的⼀个业务流程。
例如,有⼀个delivery scenario允许我们按照⾏项⽬来完成SD订单的deliveries;该delivery scenario已经在系统中定义。
这个scenario对应的事务代码是VL10C, 如下图⽰:VL10C - Sales Order Items,由Delivery process产⽣的requirements⽤user roles(也叫做list profiles)来建模,它们使我们能够调整我们的delivery list处理,它们让我们控制selection的范围,delivery list的显⽰,the type of delivery等等。
BAPI_GOODSMVT_CREATE(调拨收货发货入库退货)

BAPI_GOODSMVT_CREATE(调拨收货发货⼊库退货)code-gm_code取值:01 MB01 按采购订单的货物移动02 MB31 按⽣产订单的货物移动03 MB1A 货物提取(⼯单退料04 MB1B 转移过帐05 MB1C 其他收货06 MB11 货物移动07 MB04 "物料供应"消耗的事后调整itab-mvt_ind = 'B'. "移动标识 ⽆参考的货物移动(空)B 按采购订单的货物移动F 有关⽣产单的货物移动L 有关交货通知的货物移动K 看板需求的货物移动(WM-仅限内部)O "提供物料"消耗的后续调整W ⽐例的后续调整/产品单位物料下⾯代码都已封装为 RFC调拨单(货物移动)FUNCTION zfunction.*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" VALUE(RSTYPE) TYPE XFELD*" VALUE(RSMESG) TYPE STRING*" VALUE(O_MBLNR) TYPE MBLNR*" TABLES*" ZMES_TORDER_REQ_I STRUCTURE ZMES_TORDER_REQ_I*"----------------------------------------------------------------------*输⼊表数据:ZMES_TORDER_REQ_I(表结构)* PSTNG_DATE type BUDAT 凭证中的过帐⽇期* MATERIAL MATNR 物料号* PLANT WERKS_D CHAR ⼯⼚* MOVE_PLANT UMWRK 收货/发货⼯⼚* STGE_LOC LGORT_D 库存地点* MOVE_STLOC UMLGO 收货/发货库存地点* ENTRY_QNT ERFMG 以输⼊单位计的数量* BATCH CHARG_D 批号*"----------------------------------------------------------------------DATA:goodsmvt_header LIKE bapi2017_gm_head_01,itab TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,return LIKE TABLE OF bapiret2 WITH HEADER LINE,mat_doc LIKE bapi2017_gm_head_ret-mat_doc,req_i TYPE zmes_torder_req_i.CLEAR:goodsmvt_header.goodsmvt_header-doc_date = sy-datum. "凭证中的凭证⽇期goodsmvt_header-pr_uname = sy-datum. "⽤户名LOOP AT zmes_torder_req_i INTO req_i.MOVE-CORRESPONDING req_i TO itab.goodsmvt_header-pstng_date = req_i-pstng_date. "凭证中的过帐⽇期IF req_i-plant = req_i-move_plant.itab-move_type = '311'. "移动类型(库储存地点<->库存地点)ELSE.* itab-move_type = '301'. "移动类型(⼯⼚<->⼯⼚)ENDIF.APPEND itab.CLEAR itab.ENDLOOP.CALL FUNCTION'BAPI_GOODSMVT_CREATE'EXPORTINGgoodsmvt_header = goodsmvt_headergoodsmvt_code = '04'IMPORTINGmaterialdocument = mat_docTABLESgoodsmvt_item = itabreturn = return.READ TABLE return WITH KEY type = 'E'.IF sy-subrc = 0.rstype = 'E'.LOOP AT return WHERE type = 'E' .CONCATENATE rsmesg return-message ','INTO rsmesg.ENDLOOP.CALL FUNCTION'BAPI_TRANSACTION_ROLLBACK' . ELSE.CALL FUNCTION'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.rstype = 'S'.o_mblnr = mat_doc.ENDIF.ENDFUNCTION.⼯单发料function zfunction.*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" VALUE(RSTYPE) TYPE XFELD*" VALUE(RSMESG) TYPE STRING*" VALUE(O_MBLNR) TYPE MBLNR*" TABLES*" ZMES_ORD_REQ_I STRUCTURE ZMES_ORD_REQ_I *"----------------------------------------------------------------------*输⼊表:ZMES_ORD_REQ_I(表结构)* PLANT WERKS_D ⼯⼚* ORDERID AUFNR 订单号* MATERIAL MATNR 物料号* ENTRY_QNT ERFMG 以输⼊单位计的数量* STGE_LOC LGORT_D 库存地点*"----------------------------------------------------------------------data:goodsmvt_header like bapi2017_gm_head_01,itab type table of bapi2017_gm_item_create with header line, return like table of bapiret2 with header line,mat_doc like bapi2017_gm_head_ret-mat_doc,req_i type zmes_ord_req_i.clear:goodsmvt_header.goodsmvt_header-doc_date = sy-datum. "凭证中的凭证⽇期goodsmvt_header-pstng_date = sy-datum. "凭证中的过帐⽇期 goodsmvt_header-pr_uname = sy-datum. "⽤户名loop at zmes_ord_req_i into req_i.move-CORRESPONDING req_i to itab.itab-move_type = '261'. "移动类型(库存管理)append itab.clear itab.endloop.call function'BAPI_GOODSMVT_CREATE'exportinggoodsmvt_header = goodsmvt_headergoodsmvt_code = '03'importingmaterialdocument = mat_doctablesgoodsmvt_item = itabreturn = return.read table return with key type = 'E'.if sy-subrc = 0.rstype = 'E'.loop at return where type = 'E' .concatenate rsmesg return-message ',' into rsmesg.endloop.call function'BAPI_TRANSACTION_ROLLBACK' .else.call function'BAPI_TRANSACTION_COMMIT'exportingwait = 'X'.rstype = 'S'.o_mblnr = mat_doc.endif.endfunction.⼯单退料function zfunction.*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" VALUE(RSTYPE) TYPE XFELD*" VALUE(RSMESG) TYPE STRING*" VALUE(O_MBLNR) TYPE MBLNR*" TABLES*" ZMES_RT_ORDER_I STRUCTURE ZMES_RT_ORDER_I *"----------------------------------------------------------------------*输⼊表:ZMES_RT_ORDER_I(表结构)* PLANT WERKS_D ⼯⼚* ORDERID AUFNR 订单号* MATERIAL MATNR 物料号* RESERV_NO RSNUM 预留/相关需求的编号* RES_ITEM RSPOS 预留/相关需求的项⽬编号* ENTRY_QNT ERFMG 以输⼊单位计的数量* MOVE_REAS MB_GRBEW 移动原因* STGE_LOC LGORT_D 库存地点* BATCH CHARG_D 批号*"----------------------------------------------------------------------data:goodsmvt_header like bapi2017_gm_head_01,itab type table of bapi2017_gm_item_create with header line, return like table of bapiret2 with header line,mat_doc like bapi2017_gm_head_ret-mat_doc,order_i type zmes_rt_order_i.clear:goodsmvt_header.goodsmvt_header-doc_date = sy-datum. "凭证中的凭证⽇期goodsmvt_header-pstng_date = sy-datum. "凭证中的过帐⽇期 goodsmvt_header-pr_uname = sy-datum. "⽤户名loop at zmes_rt_order_i into order_i.move-corresponding order_i to itab.itab-move_type = '262'. "移动类型(库存管理)append itab.clear itab.endloop.call function'BAPI_GOODSMVT_CREATE'exportinggoodsmvt_header = goodsmvt_headergoodsmvt_code = '03'importingmaterialdocument = mat_doctablesgoodsmvt_item = itabreturn = return.read table return with key type = 'E'.if sy-subrc = 0.rstype = 'E'.loop at return where type = 'E' .concatenate rsmesg return-message ',' into rsmesg.endloop.call function'BAPI_TRANSACTION_ROLLBACK' .else.call function'BAPI_TRANSACTION_COMMIT'exportingwait = 'X'.rstype = 'S'.o_mblnr = mat_doc.endif.endfunction.⼯单⼊库FUNCTION zfunction.FUNCTION zmes_order_in.*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" VALUE(RSTYPE) TYPE XFELD*" VALUE(RSMESG) TYPE STRING*" VALUE(O_MBLNR) TYPE MBLNR*" TABLES*" ZMES_ORDER_IN_I STRUCTURE ZMES_ORDER_IN_I *"----------------------------------------------------------------------*输⼊表:ZMES_ORDER_IN_I(表结构)* PLANT WERKS_D ⼯⼚* ORDERID AUFNR 订单号* ENTRY_QNT ERFMG 以输⼊单位计的数量* STGE_LOC LGORT_D 库存地点* BATCH CHARG_D 批号*"----------------------------------------------------------------------DATA:header LIKE bapi2017_gm_head_01,code LIKE bapi2017_gm_code,itab TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE, return LIKE TABLE OF bapiret2 WITH HEADER LINE,mat_doc LIKE bapi2017_gm_head_ret-mat_doc,goodsmvt_serialnumber TYPE TABLE OF bapi2017_gm_serialnumber, order_in TYPE zmes_order_in_i.CLEAR:header,code.header-doc_date = sy-datum. "凭证中的凭证⽇期header-pstng_date = sy-datum. "凭证中的过帐⽇期header-pr_uname = sy-datum. "⽤户名code-gm_code = '01'.LOOP AT zmes_order_in_i INTO order_in.MOVE-CORRESPONDING order_in TO itab.itab-move_type = '101'. "移动类型itab-mvt_ind = 'F'. "移动标识APPEND itab.CLEAR itab.ENDLOOP.CALL FUNCTION'BAPI_GOODSMVT_CREATE'EXPORTINGgoodsmvt_header = headergoodsmvt_code = codeIMPORTINGmaterialdocument = mat_docTABLESgoodsmvt_item = itabgoodsmvt_serialnumber = goodsmvt_serialnumberreturn = return.READ TABLE return WITH KEY type = 'E'.IF sy-subrc = 0.rstype = 'E'.LOOP AT return WHERE type = 'E' .CONCATENATE rsmesg return-message ','INTO rsmesg.ENDLOOP.CALL FUNCTION'BAPI_TRANSACTION_ROLLBACK' .ELSE.CALL FUNCTION'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.rstype = 'S'.o_mblnr = mat_doc.ENDIF.ENDFUNCTION.ENDFUNCTION.PO退货FUNCTION zfunction.*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" VALUE(RSTYPE) TYPE XFELD*" VALUE(RSMESG) TYPE STRING*" VALUE(O_MBLNR) TYPE MBLNR*" TABLES*" ZMES_PO_STOCK_I STRUCTURE ZMES_PO_STOCK_I*"----------------------------------------------------------------------*输⼊表:ZMES_PO_STOCK_I(表结构)* MOVE_TYPE BWART 移动类型(库存管理)* PO_NUMBER BSTNR 采购订单编号* PO_ITEM EBELP 采购凭证的项⽬编号* PLANT WERKS_D ⼯⼚* MATERIAL MATNR 物料号* ENTRY_QNT ERFMG 以输⼊单位计的数量* STGE_LOC LGORT_D 库存地点* MOVE_REAS MB_GRBEW 移动原因* REF_DOC MBLNR 物料凭证编号* REF_DOC_IT LFPOS 参考凭证项⽬*"----------------------------------------------------------------------DATA:header LIKE bapi2017_gm_head_01,itab TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE, return LIKE TABLE OF bapiret2 WITH HEADER LINE,mat_doc LIKE bapi2017_gm_head_ret-mat_doc,stock_i TYPE zmes_po_stock_i.CLEAR:header.header-doc_date = sy-datum. "凭证中的凭证⽇期header-pstng_date = sy-datum. "凭证中的过帐⽇期header-pr_uname = sy-datum. "⽤户名LOOP AT zmes_po_stock_i INTO stock_i.MOVE-CORRESPONDING stock_i TO itab.itab-mvt_ind = 'B'. "移动标识CASE stock_i-move_type.WHEN '102'.itab-move_reas = ''. "移动原因WHEN '122'.WHEN '161'.itab-move_type = '101'. "移动类型itab-ref_doc = ''. "物料凭证itab-ref_doc_it = ''. "物料凭证项⽬itab-move_reas = ''. "移动原因ENDCASE.APPEND itab.CLEAR itab.ENDLOOP.CALL FUNCTION'BAPI_GOODSMVT_CREATE'EXPORTINGgoodsmvt_header = headergoodsmvt_code = '01'"MB01 按采购订单的货物移动IMPORTINGmaterialdocument = mat_docTABLESgoodsmvt_item = itabreturn = return.READ TABLE return WITH KEY type = 'E'.IF sy-subrc = 0.rstype = 'E'.LOOP AT return WHERE type = 'E' .CONCATENATE rsmesg return-message ','INTO rsmesg.ENDLOOP.CALL FUNCTION'BAPI_TRANSACTION_ROLLBACK' .ELSE.CALL FUNCTION'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.rstype = 'S'.o_mblnr = mat_doc.ENDIF.ENDFUNCTION.收货FUNCTION zfunction.*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" VALUE(RSTYPE) TYPE XFELD*" VALUE(RSMESG) TYPE STRING*" VALUE(O_MBLNR) TYPE MBLNR*" TABLES*" ZMES_PO_IN STRUCTURE ZMES_PO_IN*"----------------------------------------------------------------------*输⼊表:ZMES_PO_IN(表结构)* REF_DOC_NO XBLNR 参考凭证编号* PLANT WERKS_D ⼯⼚* PO_NUMBER EBELN 采购凭证号* PO_ITEM EBELP 采购凭证的项⽬编号* ETENS EETEN 交货计划⾏计数器* MATERIAL MATNR 物料号* STGE_LOC LGORT_D 库存地点* ENTRY_QNT ERFMG 以输⼊单位计的数量* VENDOR ELIFN 供应商帐户号* BATCH CHARG_D 批号*"----------------------------------------------------------------------DATA:header LIKE bapi2017_gm_head_01,code LIKE bapi2017_gm_code,itab TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE, return LIKE TABLE OF bapiret2 WITH HEADER LINE,mat_doc LIKE bapi2017_gm_head_ret-mat_doc,po_in TYPE zmes_po_in.CLEAR:header,code.header-doc_date = sy-datum. "凭证中的凭证⽇期header-pstng_date = sy-datum. "凭证中的过帐⽇期header-pr_uname = sy-datum. "⽤户名header-ref_doc_no = zmes_po_in-ref_doc_no. "外向交货单code-gm_code = '01'. "为 BAPI 货物移动分配事务代码 4500090063LOOP AT zmes_po_in INTO po_in.MOVE-CORRESPONDING po_in TO itab.itab-move_type = '101'. "移动类型itab-mvt_ind = 'B'. "移动标识APPEND itab.CLEAR itab.ENDLOOP.CALL FUNCTION'BAPI_GOODSMVT_CREATE'EXPORTINGgoodsmvt_header = headergoodsmvt_code = codeIMPORTINGmaterialdocument = mat_docTABLESgoodsmvt_item = itabreturn = return.READ TABLE return WITH KEY type = 'E'.IF sy-subrc = 0.rstype = 'E'.LOOP AT return WHERE type = 'E' .CONCATENATE rsmesg return-message ','INTO rsmesg.ENDLOOP.CALL FUNCTION'BAPI_TRANSACTION_ROLLBACK' .ELSE.CALL FUNCTION'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.rstype = 'S'.o_mblnr = mat_doc.ENDIF.ENDFUNCTION.IQC⼊库FUNCTION zfunction.*"----------------------------------------------------------------------*"*"Local interface:*" EXPORTING*" VALUE(RSTYPE) TYPE XFELD*" VALUE(RSMESG) TYPE STRING*" VALUE(O_MBLNR) TYPE MBLNR*" TABLES*" ZMES_PO_IQC_I STRUCTURE ZMES_PO_IQC_I*"----------------------------------------------------------------------*输⼊表:ZMES_PO_IQC_I(表结构)* PLANT WERKS_D ⼯⼚* MATERIAL MATNR 物料号* ENTRY_QNT ERFMG 以输⼊单位计的数量* STGE_LOC LGORT_D 库存地点* BATCH CHARG_D 批号*"----------------------------------------------------------------------DATA:header LIKE bapi2017_gm_head_01,itab TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,return LIKE TABLE OF bapiret2 WITH HEADER LINE,mat_doc LIKE bapi2017_gm_head_ret-mat_doc,goodsmvt_serialnumber TYPE TABLE OF bapi2017_gm_serialnumber,iqc_in TYPE zmes_po_iqc_i.CLEAR:header.header-doc_date = sy-datum. "凭证中的凭证⽇期header-pstng_date = sy-datum. "凭证中的过帐⽇期header-pr_uname = sy-datum. "⽤户名LOOP AT zmes_po_iqc_i INTO iqc_in.MOVE-CORRESPONDING iqc_in TO itab.itab-move_type = '321'. "移动类型APPEND itab.CLEAR itab.ENDLOOP.CALL FUNCTION'BAPI_GOODSMVT_CREATE'EXPORTINGgoodsmvt_header = headergoodsmvt_code = '04'"为BAPI货物移动分配事务代码(MB1B 转移过帐) IMPORTINGmaterialdocument = mat_docTABLESgoodsmvt_item = itabgoodsmvt_serialnumber = goodsmvt_serialnumberreturn = return.READ TABLE return WITH KEY type = 'E'.IF sy-subrc = 0.rstype = 'E'.LOOP AT return WHERE type = 'E' .CONCATENATE rsmesg return-message ','INTO rsmesg. ENDLOOP.CALL FUNCTION'BAPI_TRANSACTION_ROLLBACK' . ELSE.CALL FUNCTION'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.rstype = 'S'.o_mblnr = mat_doc.ENDIF.ENDFUNCTION.。
ABAP知识文章集合

创建物料组件
17
物料组件 创建 修改 删除
18
服务主数据的创建和特性的维护
19
物料组件修改BAPI:BAPI_NETWORK_COMP_CHANGE
20
BAPI_GOODSMVT_CREATE物料凭证创建与部分冲销
21
BAPI_SALESORDER_CREATEFROMDAT2创建销售订单(并修改价格)
21
合并CR:将某CR挂到另一个CR下
22
把已经释放的CR的对象包到现有CR中
23
Scan ABAP Report Sources:RS_ABAP_SOURCE_SCAN
24
执行MIRO弹出公司代码对话框 控制点
25
BC_DATA_GEN 给航班表造数据
26
Save parameters as test data(se37)
16
ALV demo:cl_salv_table
17
Demo: Disable DELETE key on Keyboard
18
REUSE_ALV_GRID_DISPLAY Refresh ALV
19
ALV_TREE 一:cl_gui_alv_tree_simple
20
ALV_TREE 二:cl_gui_simple_tree
6
parameters/select-optionstext默认长度30问题
7
获取订单状态
8
查找 export 、import memory 的位置
9
SAP Note SAR格式 解压 并打note
10
获取用户参数函数
11
工具函数:把一个工作区中非空字段值付给另一个工作区相同字段
BAPI:BAPI_PRODORDCONF_CREATE_TT

BAPI:BAPI_PRODORDCONF_CREATE_TT (TCODE:CO11NBAPI:BAPI_PRODORDCONF_CREATE_TT (TCODE:CO11N)*&---------------------------------------------------------------------**& Form FRM_PROCESS_CO11N*&---------------------------------------------------------------------** 传输数据,进⾏完⼯⼊库和消耗物料确认*----------------------------------------------------------------------** -->P_LT_MSG text* -->P_LS_IFDATAIN_ITEM text* -->P_LS_IFDATAIN_HEAD text* <--P_LV_EIND text*----------------------------------------------------------------------*FORM frm_process_co11n TABLES tp_message STRUCTURE zifsret01tp_item STRUCTURE zrmxpps002USING up_head TYPE zrmxpps001CHANGING cp_eind TYPE ccp_aufnr TYPE afko-aufnrcp_rueck TYPE afwi-rueckcp_rmzhl TYPE afwi-rmzhl.DATA:ls_item TYPE zrmxpps002,ls_message TYPE zifsret01.DATA: ls_afpo TYPE ty_afpo,ls_afpo_find TYPE ty_afpo,lt_afpo TYPE STANDARD TABLE OF ty_afpo,ls_status TYPE ty_status,lt_status TYPE STANDARD TABLE OF ty_status.DATA: lv_index TYPE i.*--------------------------------------------------------------------**1 根据销售合同和⾏号,取得对应的⽣产订单号IF up_head-vtype = cns_vtype_1 OR "对外销售-⾮来料加⼯类型合同up_head-vtype = cns_vtype_2. "对外销售-来料加⼯类型合同"1,2为对外销售,需要根据销售订单号及⾏号读取对应的⽣产订单SELECT p~aufnr p~posnrINTO TABLE lt_afpoFROM afpo AS pWHERE p~kdauf = up_head-vbelnAND p~kdpos = up_head-posnr.IF sy-subrc NE 0.CLEAR ls_message.ls_message-class = 'BUS'.ls_message-msgtyp = 'E'.ls_message-msgno = '101'.ls_message-msgtxt = '根据销售合同和⾏号未找到相应的SAP⽣产订单号!'.APPEND ls_message TO tp_message.cp_eind = 'X'.ENDIF.ELSEIF up_head-vtype = cns_vtype_3. "站内⾃⽤"站内⾃⽤,需要根据⽣产出的物料的编码和⼯⼚来找出合适的⽣产订单SELECT a~aufnr a~posnrINTO TABLE lt_afpoFROM afpo AS a INNER JOIN aufk AS b ON b~aufnr = a~aufnrWHERE a~matnr = up_head-matnrAND a~pwerk = up_head-werks "计划⼯⼚,todo 可能要⽤⽣产⼯⼚ AND b~auart = 'ZR02'. "RMX⾃⽤⽣产订单IF sy-subrc NE 0.CLEAR ls_message.ls_message-class = 'BUS'.ls_message-msgtyp = 'E'.ls_message-msgno = '102'.ls_message-msgtxt = '根据物料号+⼯⼚未找到相应的SAP⽣产订单号!'. APPEND ls_message TO tp_message.cp_eind = 'X'.ENDIF.ELSE.CLEAR ls_message.ls_message-class = 'BUS'.ls_message-msgtyp = 'E'.ls_message-msgno = '103'.ls_message-msgtxt = '销售合同类型定义错误!'.APPEND ls_message TO tp_message.cp_eind = 'X'.ENDIF.CHECK cp_eind NE 'X'."合并对象号FIELD-SYMBOLS: LIKE ls_afpo.LOOP AT lt_afpo ASSIGNING .CONCATENATE 'OR' -aufnr INTO -objnr.ENDLOOP.*--------------------------------------------------------------------**2 判断⽣产订单的状态,找到⼀个合适的⽣产订单SORT lt_afpo BY objnr."读取状态SELECT objnr stat inactINTO TABLE lt_statusFROM jestFOR ALL ENTRIES IN lt_afpoWHERE objnr EQ lt_afpo-objnrAND inact EQ space.* "删除未激活的状态* DELETE lt_status WHERE inact = 'X'."删除不需要的状态DELETElt_statusWHERE"txt04NE'REL'********** txt04 NE 'CLSD' AND* txt04 NE 'TECO'.stat NE 'I0045' AND "TECOstat NE 'I0046' AND "CLSDstat NE 'E0001'. "10SORT lt_status BY objnr stat.*--------------------------------------------------------------------**3 ⽣产订单的状态中必须包括TECO、不包括CLSDCLEAR ls_afpo_find.LOOP AT lt_afpo INTO ls_afpo.lv_index = sy-tabix."系统状态必须包含TECOREAD TABLE lt_status TRANSPORTING NO FIELDSWITH KEY objnr = ls_afpo-objnrstat = 'I0045'BINARY SEARCH.IF sy-subrc NE 0.DELETE lt_afpo INDEX lv_index.CONTINUE.ENDIF."系统状态必须不包含CLSDREAD TABLE lt_status TRANSPORTING NO FIELDSWITH KEY objnr = ls_afpo-objnrstat = 'I0046'BINARY SEARCH.IF sy-subrc EQ 0.DELETE lt_afpo INDEX lv_index.CONTINUE.ENDIF."⽤户状态必须为10READ TABLE lt_status TRANSPORTING NO FIELDSWITH KEY objnr = ls_afpo-objnrstat = 'E0001'BINARY SEARCH.IF sy-subrc NE 0.DELETE lt_afpo INDEX lv_index.CONTINUE.ENDIF."找到⽣产订单,退出循环ls_afpo_find = ls_afpo.EXIT.ENDLOOP.IF ls_afpo_find IS INITIAL.CLEAR ls_message.ls_message-class = 'BUS'.ls_message-msgtyp = 'E'.ls_message-msgno = '104'.ls_message-msgtxt = '没有符合要求状态的⽣产订单!'.APPEND ls_message TO tp_message.cp_eind = 'X'.ENDIF.CHECK cp_eind NE 'X'.cp_aufnr = ls_afpo_find-aufnr.*--------------------------------------------------------------------**4 Call BAPIDATA: ls_propose LIKE bapi_pp_conf_prop.DATA: lt_time TYPE STANDARD TABLE OF bapi_pp_timeticket,ls_time TYPE bapi_pp_timeticket,ls_goods TYPE bapi2017_gm_item_create,lt_goods TYPE STANDARD TABLE OF bapi2017_gm_item_create, ls_link TYPE bapi_link_conf_goodsmov,lt_link TYPE STANDARD TABLE OF bapi_link_conf_goodsmov, lt_return_detail TYPE STANDARD TABLE OF bapi_coru_return, ls_return_detail TYPE bapi_coru_return,ls_return TYPE bapiret1.*--------------------------------------------------------------------**4.1 需要更新的数据设置ls_propose-quantity = 'X'.ls_propose-date_and_time = 'X'.ls_propose-goodsmovement = 'X'.*--------------------------------------------------------------------**4.2 timeticketCLEAR ls_time.ls_time-orderid = ls_afpo_find-aufnr. "⽣产订单号ls_time-operation = '0010'. "⼯序号:0010ls_time-postg_date = up_head-budat. "记账⽇期ls_time-yield = up_head-menge. "⽣产数量*ls_time-conf_quan_unit = 'PC'.*ls_time-conf_quan_unit_iso = 'PC'.APPEND ls_time TO lt_time.*--------------------------------------------------------------------**4.3 goodsmovements* 第⼀次赋值,⽤于获取相关默认值CLEAR ls_goods.ls_goods-orderid = ls_afpo_find-aufnr. "⽣产订单号ls_goods-order_itno = '0010'. "⼯序号:0010* VAL_TYPE 评估类型APPEND ls_goods TO lt_goods.*4.4 调⽤BAPI,获取默认值CLEAR: ls_return.CALL FUNCTION 'BAPI_PRODORDCONF_GET_TT_PROP'EXPORTINGpropose = ls_proposeIMPORTINGreturn = ls_returnTABLEStimetickets = lt_timegoodsmovements = lt_goodslink_conf_goodsmov = lt_linkdetail_return = lt_return_detail.IF ls_return-type = 'E' ORls_return-type = 'A'.CLEAR ls_message.ls_message-class = 'BUS'.ls_message-msgtyp = ls_return-type.ls_message-msgno = ls_return-number.ls_message-msgtxt = ls_return-message.APPEND ls_message TO tp_message.cp_eind = 'X'.ENDIF.LOOP AT lt_return_detail INTO ls_return_detailWHERE type IS NOT INITIAL.CLEAR ls_message.ls_message-class = 'BUS'.ls_message-msgtyp = ls_return_detail-type.ls_message-msgno = ls_return_detail-number.ls_message-msgtxt = ls_return_detail-message.APPEND ls_message TO tp_message.IF ls_return_detail-type = 'E' ORls_return_detail-type = 'A'.cp_eind = 'X'.ENDIF.ENDLOOP.CHECK cp_eind NE 'X'.*4.5 若来⾃RMX系统的信息显⽰⽣产订单对应的销售合同为来料加⼯,* 则需要由接⼝程序将默认带出的评估类型PRD改为OEMLOOP AT lt_goods INTO ls_goods.IF up_head-vtype = cns_vtype_2.ls_goods-val_type = 'OEM'.ELSE.ls_goods-val_type = 'PRD'.ENDIF.MODIFY lt_goods FROM ls_goods TRANSPORTING val_type.ENDLOOP.*4.6 准备⾏项⽬数据"lt_goods中已经有⽣产订单对应的⼀条⾏记录,需要将传输的消耗物料信息 "添加到内表中,进⾏确认,⽣成物料凭证CLEAR: ls_return, lt_return_detail." 产量,lt_time 中默认是⽣产订单剩余未确认的产量LOOP AT lt_time INTO ls_time.ls_time-yield = up_head-menge. "产量ls_time-postg_date = up_head-budat. "记账⽇起MODIFY lt_time FROM ls_time TRANSPORTING yield postg_date.ENDLOOP."⽣产的物料,数量默认为未确认的全部数量LOOP AT lt_goods INTO ls_goods.ls_goods-entry_qnt = up_head-menge. "产量MODIFY lt_goods FROM ls_goods TRANSPORTING entry_qnt.ENDLOOP.LOOP AT tp_item INTO ls_item.lv_index = sy-tabix.CLEAR ls_goods.ls_goods-material = ls_item-matnr.ls_goods-move_type = '261'.ls_goods-plant = ls_item-werks.ls_goods-stge_loc = ls_item-lgort. "'0001'.ls_goods-entry_qnt = ls_item-menge.ls_goods-entry_uom = ls_item-meins.* ls_goods-entry_uom_iso = 'PCE'.APPEND ls_goods TO lt_goods.CLEAR ls_link.ls_link-index_confirm = 1.ls_link-index_goodsmov = lv_index + 1.APPEND ls_link TO lt_link.ENDLOOP.CALL FUNCTION 'BAPI_PRODORDCONF_CREATE_TT'* EXPORTING* POST_WRONG_ENTRIES = '0'* testrun = ''IMPORTINGreturn = ls_returnTABLEStimetickets = lt_timegoodsmovements = lt_goodslink_conf_goodsmov = lt_linkdetail_return = lt_return_detail.IF ls_return-type = 'E' ORls_return-type = 'A'.CLEAR ls_message.ls_message-class = 'BUS'.ls_message-msgtyp = ls_return-type.ls_message-msgno = ls_return-number.ls_message-msgtxt = ls_return-message.APPEND ls_message TO tp_message.cp_eind = 'X'.ENDIF.LOOP AT lt_return_detail INTO ls_return_detailWHERE type IS NOT INITIAL.CLEAR ls_message.ls_message-class = 'BUS'.ls_message-msgtyp = ls_return_detail-type.ls_message-msgno = ls_return_detail-number.CONCATENATE ls_return_detail-message';确认号:' ls_return_detail-conf_no';计数器:' ls_return_detail-conf_cntINTO ls_message-msgtxt .APPEND ls_message TO tp_message.IF ls_return_detail-type = 'E' ORls_return_detail-type = 'A'.cp_eind = 'X'.ELSE.IF ls_return_detail-conf_no IS NOT INITIAL.cp_rueck = ls_return_detail-conf_no. "确认号cp_rmzhl = ls_return_detail-conf_cnt. "计数器ENDIF.ENDIF.ENDLOOP.IF cp_eind NE 'X'.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.ELSE.CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF.CHECK cp_eind NE 'X'.CLEAR afwi.DO 5 TIMES.SELECT SINGLE *FROM afwiWHERE rueck = cp_rueckAND rmzhl = cp_rmzhl.* IF sy-subrc EQ 0.IF afwi-mjahr IS NOT INITIAL.EXIT.ELSE.WAIT UP TO 1 SECONDS.ENDIF.ENDDO.IF afwi IS INITIAL.ls_message-class = 'BUS'.ls_message-msgtyp = 'W'.ls_message-msgno = '000'.ls_message-msgtxt = '⽣产完⼯⼊库物料凭证未⽣成成功,请⼈⼯处理!'. APPEND ls_message TO tp_message.ENDIF.ENDFORM. " FRM_PROCESS_CO11N。
BAPI_GOODSMVT_CREATE

FU BAPI_GOODSMVT_CREATE GOODSMVT_CODE____________________________________________________Short TextAssign Code to Transaction for Goods MovementDescriptionThis parameter transfers the new key assignment of the GM_CODE to the relevant transactions in Inventory Management.For more information on the individual parameter fields, see the data element documentation in the ABAP Dictionary.Function ModuleBAPI_GOODSMVT_CREATEPost goods movements with MB_CREATE_GOODS_MOVEMENT FunctionalityYou can use this method to create a material document for a goods movement.You can only create one material document each time you call up the method.You can use a simulation function before posting the goods movement to check how the data is updated in the database. The standard system is configured so that the goods movement is posted immediately, without prior simulation.Ensure that you transfer the data in the same way as it is managed in the database. For example:∙Material number 18-character with leading zeros∙Batches with uppercase lettersEnsure that the header data of the material document includes the posting date for all transactions/events listed below. Populate the PSTNG_DATE field (import structure GOODSMVT_HEADER) in the interfaceBAPI2017_GM_HEAD_01 for this purpose.NotesFrom Release ERP2005 onwards, it is possible to populate customers' own fields in database tables using the BAPI, without carrying out a modification.The enhancements are passed on to the BAPI in a container and can be processed within the BAPI function module.Technically, this is realized via an extension parameter (ExtensionIn) (see below or tab page 'Tables -> Long Text') .Authorization checkIn the MM Inventory Management component, the method does not perform any authorization checks.Note that the system can also check authorization objects of other applications during the posting of a goods movement, depending on the business transaction.TransferThe following information about the material document that is to be created is passed on to the method:∙ A structure with the header data∙ A structure with the code for the movement∙ A table with the item data∙ A table with the serial numbersThe posting is made by the function module MB_CREATE_GOODS_MOVEMENT.ConfirmationsMessages are returned in the Return parameter. The parameter documentation shows the return codes and their meanings.Further informationThe method can only perform your function if no error messages were generated in the Return table. This is the case if the header data and all the items were processed successfully.Transaction control is not implemented. The calling program therefore has to execute the Commit Work itself after this method has been successfully invoked (in other words, if no errors were reported in the Return parameter).Which fields must be populated during the various transactions/events?The following example scenarios illustrate which fields have to be populated for which business transactions/events (code).There are the following types of transactions/events:1. GM_Code 01: Goods receipt for purchase order2. GM_Code 02: Goods receipt for production order3. GM_Code 03: Goods issue4. GM_Code 04: Transfer posting5. GM_Code 05: Other goods receipt6. GM_Code 06: Reversal of goods movements7. GM_Code 07: Subsequent adjustment with regard to a subcontract orderEntering the movement indicatorDepending on the transaction, you must enter the following in the movement indicator field:∙GM_Code 01 (Goods receipt for purchase order): B∙GM_Code 02 (Goods receipt for production order): F∙For all other transactions, leave the field blank.For 1: GM_Code 01: Goods receipt for purchase order∙Purchase order knownThe following fields must be populated:o Purchase ordero Purchase order itemo Movement typeo Movement indicatoro Quantity in unit of entryo ISO code unit of measurement for unit of entry orquantity proposalThe following fields may have to be populated (this is not a complete list):o Minimum shelf life expiration date (if set up in the system)o Reason for movement (if set up in the system)o Batch (if the material is handled in batches and no automatic batch assignment has been set up)o Storage location (if no storage location us specified in the purchase order item)The following fields can be populated (this is not a complete list):o Stock typeo Item texto Unloading pointo Delivery completed indicatorThe following fields must not be populated (this is not a complete list):o Account assignment fields (the account assignment is adopted from the purchase order)o Reservationo Receiving/issuing materialo Receiving/issuing planto Receiving/issuing storage locationIn the case of a purchase order item with the item category "subcontracting", only the GR item is to be passed on in the interface. The GI items are determined automatically in the system.Purchase order unknown: Shipping notification knownThe following fields must be populated:o Deliveryo Delivery itemo Movement typeOther fields as under "Purchase order known". The system determines the relevant purchase order item via the delivery/delivery item.Purchase order unknown: Purchase order is to be created automaticallyThe following fields must be populated:o Material numbero Planto Storage locationo Vendoro Movement typeo Movement indicatoro Quantity in unit of entryo ISO code unit of measurement for unit of entryThe following fields may have to be populated (this is not a complete list):o Minimum shelf life expiration date (if set up in the system)o Reason for movement (if set up in the system)o Batch (if the material is handled in batches and batches are not assigned automatically)The following fields can be populated (this is not a complete list):o Stock typeo Item texto Unloading pointYou cannot populate the following fields (this is not a complete list):o Account assignment fields (automatic creation of purchase order items with account assignment is not supported)o Reservationo Receiving/issuing materialo Receiving/issuing planto Receiving/issuing storage locationPurchase order unknown: A purchase order is not to be createdThe following fields must be populated:o Material numbero Planto Storage locationo Vendoro Movement typeo Movement indicatoro Quantity in unit of entryo ISO code unit of measurement for unit of entryThe following fields may have to be populated in some cases (this is not a complete list)o Minimum shelf life expiration date (if set up in the system)o Reason for movement (if set up in the system)o Batch (if the material is handled in batches and automatic assignment of batch numbers is not set)The following fields can be populated (this is not a complete list)o Special stock indicatoro Item texto Unloading pointo Goods recipientThe following fields cannot be populated (this is not a complete list)o Account assignment fields (automatic creation of purchase order items with account assignment is not supported)o Reservationo Receiving/issuing materialo Receiving/issuing planto Receiving/issuing storage locationo Receiving/issuing batchThe input combinations listed above for the GM_CODE 01 can be combined within an input table so that they can be posted in a material document. Items can also be posted for different purchase orders, provided that all the purchase orders relate to the same vendor.∙Transfer of subcontracting componentsWhen the end product (ordered material of a subcontract order) is posted using movement type 101, the populated unique identification of the document line (LINE_ID) is additionally needed for the transfer of the subcontracting components.More information on LINE_ID and PARENT_IDThe following fields must be populated for the components:o Unique identification of the document lineo Identification of the immediately superordinate lineo Material numbero Planto Storage locationo Quantity in unit of entryThe following fields can be filled for the components:o All other fields in the method that are included in this list.The following fields cannot be populated for the components:o All fields that are not included in the list above. The movement indicator must be initial.∙Additional fields in goods-receipt-based invoice verificationWhen you post a goods receipt to purchase order with movement type 102, an issue with reference to a previously posted goods issue, the following fields must also be transferred:o REF_DOC_IT (LFPOS): Item of a reference documento REF_DOC (LFBNR): Document number of a reference documento REF_DOC_YR (LFBJA): Fiscal year of a reference documentOnly if you transfer these fields can you be sure that the link to the original goods movement is retained. For 2 GM_Code 02: Goods receipt for production orderThe following fields have to be populated:o Ordero Movement typeo Movement indicatoro Quantity in unit of entryo ISO code unit of measurement for unit of entry orquantity proposalThe following fields may have to be populated in some cases (this is not a complete list): o Minimum shelf life expiration date (if set up in the system)o Reason for movement (if set up in the system)o Batch (if the material is handled in batches and automatic batch number assignment is not set)o Storage location (if storage location has not been specified in the order)The following fields can be populated (this is not a complete list):o Order item (co-product)o Stock typeo Item texto Unloading pointo"Delivery completed" indicatorThe following fields cannot be populated (this is not a complete list):o Account assignment fields (the account assignments are adopted from the purchase order)o Reservationo Receiving/issuing materialo Receiving/issuing planto Receiving/issuing storage locationo Receiving/issuing batchFor 3 GM_Code 03: Goods issueGoods issue without reference to a reservationThe following fields must be populated:o Material numbero Planto Storage locationo Movement typeo Movement indicatoro Quantity in unit of entryo ISO code unit of measurement for unit of entryThe following fields may have to be populated in some cases (this is not a complete list): o Special stock (e.g. sales order, project, vendor etc.)o Minimum shelf life expiration date (if set up in the system)o Reason for movement (if set up in the system)o Batch (if the material is handled in batches and automatic batch number assignment is not set)o Account assignment fieldsThe following fields can be populated (this is not a complete list):o Special stock indicatoro Item texto Unloading pointo Goods recipientThe following fields cannot be populated (this is not a complete list):o Reservationo Receiving/issuing materialo Receiving/issuing planto Receiving/issuing storage locationo Receiving/issuing batchGoods issue with reference to a reservationThe following fields must to be populated:o Reservation numbero Reservation itemo Record type of the reservationo Movement indicatoro Quantity in unit of entryo ISO code unit of measurement for unit of entryThe following fields may have to be populated in some cases (this is not a complete list): o Minimum shelf life expiration date (if set up in the system)o Reason for movement (if set up in the system)o Batch (if the material is handled in batches and automatic batch number assignment is not set) o Storage location (if not planned in the reservation)The following fields can be populated (this is not a complete list):o Special stock indicatoro Item texto Unloading pointo Goods recipientThe following fields cannot be populated (this is not a complete list):o Movement typeo Materialo Planto Account assignment fieldsFor 4 GM_Code 04: Transfer postingTransfer posting without reference to a reservationThe following fields must be populated:o Material numbero Planto Storage locationo Movement typeo Movement indicatoro Quantity in unit of entryo ISO code unit of measurement for unit of entryThe following fields may have to be populated in some cases (this is not a complete list): o Receiving materialo Receiving planto Receiving storage locationo Receiving batch (if material is handled in batches and you want to change batches)o Receiving/issuing special stock (e.g. sales order, project, vendor etc.)o Minimum shelf life expiration date (if set up in the system)o Reason for movement (if set up in the system)o Batch (if the material is handled in batches and automatic batch number assignment is not set) The following fields can be populated (this is not a complete list):o Special stock indicatoro Item texto Account assignment fields (for automatic posting lines: expense/income from stock transfer) The following fields cannot be populated (this is not a complete list):o Reservation∙Transfer posting with reference to a reservationSee goods issue with reference to a reservationFor 5 GM_Code 05: Other goods receipts∙Other goods receipt without reference to a reservationSee goods issue without reference to a reservation∙Other goods receipt with reference to a reservationSee goods issue with reference to a reservationFor 6 GM_Code 06: Reversal of goods movementsYou can use the Cancel method to reverse goods movements. But you may also want to cancel agoods movement without referring to a material document (see the Cancel method).If you want to work without referring to the document, you have to populate theBAPI_GM_ITEM_CREATE-XSTOB field in the interface (import table GOODSMVT_ITEM). In this case, the system converts the movement type assigned in the interface to the reversal movement type.Alternatively, you can set the reversal movement type in the interface. In this case, theBAPI_GM_ITEM_CREATE_XSTOB field must be transferred blank.If you want to cancel a goods movement with reference to a reservation (without using the Cancelmethod) you can only transfer the BAPI_GM_ITEM_CREATE_XSTOB field if it is populated. Movement types are not transferred when you post with reference to a reservation, as the movement type iscontained in the reservation item.For 7. GM_Code 07: Subsequent adjustment with regard to a subcontract order∙Ordered material of subcontract orderThe following fields must be populated:o Unique identification of document line (can be freely assigned)o Posting date in document headero Document number of purchasing documento Item number of purchasing documento Material numbero Planto Movement type (select movement type 121)o Movement indicator (must be O)Further entries are not allowed. The entry quantity for the ordered material of a subcontract order must be zero.∙ComponentsThe following fields must be populated:o Unique identification of document line (can be freely assigned)o Identification of the immediately superordinate lineo Planto Material numbero Quantity in unit of entry; can also be negativeThe following fields can be populated:o Storage locationo All other fields in the method that are included in this list.The following fields may not be populated:o All fields that are not in the list above. The movement indicator must be blank.More information on LINE_ID and PARENT_IDAdditional fields in goods-receipt-based invoice verificationWhen you post a subsequent adjustment, the following fields must also be transferred: o REF_DOC_IT (LFPOS): Item of a reference documento REF_DOC (LFBNR): Document number of a reference documento REF_DOC_YR (LFBJA): Fiscal year of a reference documentOnly if you transfer these fields can you be sure that the link to the original goods movement is retained.。