SAP ABAP常用BAPI : BAPI_PO_CREATE1创建采购订单使用说明<转载>(NO_PRICE_FROM_PO参数)
原文连接https://mp.weixin.qq.com/s/Rv3Tj_Wwkvdqa8caN45TTwBAPI_PO_CREATE1是SAP系统中用于创建采购订单的标准BAPI。参数结构与关键字段采购订单抬头POHEADER包含订单类型、供应商、凭证日期、货币等字段。采购订单行项目POITEM定义物料、数量、价格、工厂等行项目信息。行项目编号需在同一个采购订单中连续递增交货计划行POSCHEDULE指定交货日期和数量但需注意 sched_line字段通常不应设置否则可能导致采购数量异常。采购订单账务分配POACCOUNT包含成本中心、会计科目、订单等等返回参数RETURN包含执行结果信息如成功或错误消息。大家在用这个BAPI创建采购订单虽然能成功创建采购订单但是你可能会发现行项目的净价总是和自己导入的数据不对要么总是取采购信息记录维护的净价要么就会采用上一个采购订单的净价。上面这样问题要通过这个BAPI的下面2个参数的设置解决1、NO_PRICE_FROM_PO2、POITEM-PO_PRICE下面详细介绍下这两参数的控制功能在NO_PRICE_FROM_PO ‘X’ 的前提下POITEM-PO_PRICE ’ 空值条件将自动确定仅当系统无法确定条件时才会复制 NET_PRICE 字段中的值。即有采购信息记录取采购信息记录价格如果没有取BAPI中NET_PRICE字段给定的值。POITEM-PO_PRICE ‘1’字段 NET_PRICE 中传输的值将复制为总价即该值会通过计算方案中指定为基本价格的条件类型进行设定。在 SAP 标准系统中对应的条件类型为 PB00 或 PBXX。所有其他条件类型保持不变不会从最近的凭证中复制任何条件。即无论有无采购信息记录都是取BAPI中POITEM-PO_PRICE字段给定的值其它条件类型保持不变。POITEM-PO_PRICE ‘2’字段POITEM-PO_PRICE中传输的值将复制为净价即该值会通过计算流程中指定为基本价格的条件类型进行设定。所有其他条件类型均被删除。即无论有无采购信息记录都是取BAPI中POITEM-PO_PRICE字段给定的值其它条件类型被删除如下图只有PBXX。为了更好理解BAPI_PO_CREATE1的使用功能大家可以使用如下的测试程序进行测试下。*---------------------------------------------------------------------**Reportz_create_po_bapi*---------------------------------------------------------------------**---------------------------------------------------------------------*report z_create_po_bapi.data:ls_poheader type bapimepoheader,ls_poheaderx type bapimepoheaderx,lt_poitem type table of bapimepoitem,ls_poitem type bapimepoitem,lt_poitemx type table of bapimepoitemx,ls_poitemx type bapimepoitemx,lt_poaccount type table of bapimepoaccount,ls_poaccount type bapimepoaccount,lt_poaccountx type table of bapimepoaccountx,ls_poaccountx type bapimepoaccountx,lt_return type table of bapiret2,ls_return type bapiret2,lv_ebeln type ebeln.*1.填充采购订单头数据 ls_poheader-doc_typeNB. 采购订单类型 ls_poheader-vendor0000001000. 供应商 ls_poheader-purch_org2800. 采购组织 ls_poheader-comp_code2800. 公司代码 ls_poheader-pur_groupCN2. 公司代码 ls_poheader-doc_datesy-datum. 凭证日期 ls_poheader-created_bysy-uname. 创建者*标识哪些头字段被修改 ls_poheaderx-doc_typeX.ls_poheaderx-vendorX.ls_poheaderx-purch_orgX.ls_poheaderx-comp_codeX.ls_poheaderx-pur_groupX. 公司代码 ls_poheaderx-doc_dateX.ls_poheaderx-created_byX.*2.填充采购订单项目数据 ls_poitem-po_item00010. 项目编号 ls_poitem-material100-100. 物料编号 ls_poitem-quantity10. 数量 ls_poitem-po_unitPC. 单位 ls_poitem-net_price125.50. 净价 ls_poitem-po_price1.ls_poitem-plant2800. 工厂 append ls_poitemtolt_poitem.*标识哪些项目字段被修改 ls_poitemx-po_item00010.ls_poitemx-materialX.ls_poitemx-quantityX.ls_poitemx-po_unitX.ls_poitemx-net_priceX.ls_poitemx-po_priceX.ls_poitemx-plantX.append ls_poitemxtolt_poitemx.*3.填充账户分配数据如需要 ls_poaccount-po_item00010. 对应项目编号 ls_poaccount-serial_no01. 序列号 ls_poaccount-costcenter100000. 成本中心 ls_poaccount-quantity10. 数量 append ls_poaccounttolt_poaccount.ls_poaccountx-po_item00010.ls_poaccountx-serial_no01.ls_poaccountx-costcenterX.ls_poaccountx-quantityX.append ls_poaccountxtolt_poaccountx.*4.调用BAPI创建采购订单 call function BAPI_PO_CREATE1 exporting poheaderls_poheader poheaderxls_poheaderx testrun 测试运行实际创建X仅测试不创建 no_price_from_poXtablesreturnlt_return poitemlt_poitem poitemxlt_poitemx*poaccountlt_poaccount*poaccountxlt_poaccountx.*5.检查返回结果 read table lt_returnwithkeytypeEtransporting no fields.ifsy-subrc0. 无错误提交事务 call function BAPI_TRANSACTION_COMMIT exporting waitX. 获取创建的采购订单号 read table lt_return into ls_returnwithkeytypeSfieldlv_ebeln.ifsy-subrc0.write:/采购订单创建成功,ls_return-message_v2.endif.else. 有错误回滚事务 call function BAPI_TRANSACTION_ROLLBACK.*输出错误消息 loop at lt_return into ls_return where typeEor typeA.write:/错误:,ls_return-message.endloop.endif.