SAP的BAPI_PO_CREATE1创建采购订单 创建以及问题

*&---------------------------------------------------------------------*
*& Report ZLJRTEST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zljrtest.

DATA: l_po_item(5) TYPE n.
DATA: l_temp       TYPE string.
DATA: ls_po_header    LIKE bapimepoheader,
      ls_poheaderx    LIKE bapimepoheaderx,
      ls_poaddrvendor LIKE  bapimepoaddrvendor.

DATA: lt_po_items          LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,
      lt_po_item_schedules LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE,
      lt_poaccount         LIKE bapimepoaccount OCCURS 0 WITH HEADER LINE,
      lt_return            LIKE  bapiret2 OCCURS 0 WITH HEADER LINE,
      lt_itemx             LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE,
      lt_schedulx          LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE,
      lt_poaccountx        LIKE bapimepoaccountx OCCURS 0 WITH HEADER LINE.
DATA: lt_pocond  LIKE bapimepocond OCCURS 0 WITH HEADER LINE,
      lt_pocondx LIKE bapimepocondx OCCURS 0 WITH HEADER LINE.

DATA:lt_potextheader LIKE bapimepotextheader OCCURS 0 WITH HEADER LINE,
     lt_potextitem   LIKE bapimepotext OCCURS 0 WITH HEADER LINE.

DATA: lt_pocomponents  LIKE bapimepocomponent OCCURS 0 WITH HEADER LINE,
      lt_pocomponentsx LIKE bapimepocomponentx OCCURS 0 WITH HEADER LINE.
DATA: l_msg TYPE string.
DATA: rt_flag(1) TYPE c.

DATA:lv_ebeln TYPE bapimepoheader-po_number.

REFRESH: lt_po_items,lt_po_item_schedules,lt_return,
         lt_itemx,lt_schedulx.

*CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
*  EXPORTING
*    input  = ilifnr
*  IMPORTING
*    output = ilifnr.

DATA:input  TYPE  zdt_srm_create_po_req_input.

"抬头信息
ls_po_header-comp_code  = '1000'.      "公司代码
ls_po_header-doc_type   = 'Z02'.       "凭证类型
ls_po_header-creat_date = sy-datum.    "创建日期
ls_po_header-vendor     = '0000600000'."供应商
ls_po_header-purch_org  = '1000'.      "采购组织
ls_po_header-pur_group  = '201'.       "采购组
ls_po_header-currency   = 'CNY'.       "货币码
ls_po_header-doc_date   = sy-datum.    "采购凭证日期
ls_po_header-created_by = sy-uname.    "当前用户
ls_po_header-comp_code  = '1000'. "公司代码
ls_po_header-doc_type   = 'Z01'. "凭证类型
ls_po_header-creat_date = sy-datum.    "创建日期
ls_po_header-ref_1      = '1213'. "贵方参考
ls_po_header-created_by = sy-uname.    "当前用户

*抬头文本headtext  抬头文本
CLEAR:Lt_potextheader.
lt_potextheader-po_item = '00000'.
lt_potextheader-text_id = 'F01'.
lt_potextheader-text_form = '*'.
lt_potextheader-text_line = '测试'.
APPEND lt_potextheader.

ls_poheaderx-comp_code   = 'X'.
ls_poheaderx-doc_type    = 'X'.
ls_poheaderx-creat_date  = 'X'.
ls_poheaderx-vendor      = 'X'.
ls_poheaderx-purch_org   = 'X'.
ls_poheaderx-pur_group   = 'X'.
ls_poheaderx-currency    = 'X'.
ls_poheaderx-doc_date    = 'X'.
ls_poheaderx-created_by  = 'X'.
ls_poheaderx-comp_code   = 'X'.
ls_poheaderx-doc_type    = 'X'.
ls_poheaderx-creat_date  = 'X'.
ls_poheaderx-vendor      = 'X'.
ls_poheaderx-purch_org   = 'X'.
ls_poheaderx-pur_group   = 'X'.
ls_poheaderx-currency    = 'X'.
ls_poheaderx-doc_date    = 'X'.
ls_poheaderx-ref_1       = 'X'.
ls_poheaderx-created_by  = 'X'.

"供应商地址信息
ls_poaddrvendor-name        = 'liao'      ."名称
ls_poaddrvendor-street      = '集美区'     ."街道
ls_poaddrvendor-house_no    = '179' ."门牌号
ls_poaddrvendor-postl_cod1  = '514500' ."邮政编码
ls_poaddrvendor-city        = '厦门'     ."城市
ls_poaddrvendor-country     = '中国'    ."国家
ls_poaddrvendor-tel1_numbr  = '21213'."电话
ls_poaddrvendor-tel1_ext    = '0514' ."分机号

*LOOP AT input-item INTO DATA(ls_item).

  "行项目号
  l_po_item              = l_po_item + 10.
  lt_po_items-po_item    = l_po_item.

*  IF ls_item-matnr IS NOT INITIAL.
    lt_po_items-material   = '000000000000123311'.  " 物料号
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input  = lt_po_items-material
      IMPORTING
        output = lt_po_items-material.

*  ENDIF.

  lt_po_items-acctasscat = ' '.    " 科目类别分配
  lt_po_items-item_cat   = '0'.    " 项目类别
  lt_po_items-short_text = '什么测试'.    " 短文本
  lt_po_items-quantity   = 11.    " 采购订单数量
  lt_po_items-po_unit    = 'KG'.    " 订单单位
  lt_po_items-price_unit = 1.    " 价格单位
  lt_po_items-orderpr_un = 'KG'.    " 订单价格单位(采购)
  lt_po_items-net_price  = '11'.    " 净价
  lt_po_items-matl_group = '111132'.    " 物料组
  lt_po_items-plant      = '1001'.    " 工厂
  lt_po_items-trackingno = '12345678'.    " 需求跟踪编号
  lt_po_items-preq_name  = sy-uname.    " 申请者
  lt_po_items-gr_basediv = ''.    " 基于收货的发票校验
  lt_po_items-costcenter = '1001'.    " 成本中心
  lt_po_items-gl_account = '11000'.    " 总账科目
  lt_po_items-tax_code   = 'J1'.

  lt_po_items-no_rounding   = 'X'. "以输入数量为准,不使用SAP建议舍入的数量
  APPEND lt_po_items.
  CLEAR lt_po_items.

  lt_itemx-po_item     = l_po_item.
  lt_itemx-po_itemx    = 'X'.
  lt_itemx-material    = 'X'.
  lt_itemx-acctasscat  = 'X'.
  lt_itemx-item_cat    = 'X'.
  lt_itemx-short_text  = 'X'.
  lt_itemx-quantity    = 'X'.
  lt_itemx-po_unit     = 'X'.
  lt_itemx-price_unit  = 'X'.
  lt_itemx-orderpr_un  = 'X'.
  lt_itemx-net_price   = 'X'.
  lt_itemx-matl_group  = 'X'.
  lt_itemx-plant       = 'X'.
  lt_itemx-trackingno  = 'X'.
  lt_itemx-preq_name   = 'X'.
  lt_itemx-gr_basediv  = 'X'.
  lt_itemx-costcenter  = 'X'.
  lt_itemx-gl_account  = 'X'.
  lt_itemx-tax_code    = 'X'.

  APPEND lt_itemx.CLEAR  lt_itemx.

  CLEAR  lt_poaccount.
  lt_poaccount-po_item    = l_po_item.
  lt_poaccount-costcenter = '1001'.    " 成本中心
  lt_poaccount-gl_account = '11000'.    " 总账科目
  lt_poaccount-quantity   = 11.
  lt_poaccount-asset_no   = '110300000001'.   " 固定资产编号
  lt_poaccount-tax_code   = 'J1'.   " 税码
  lt_poaccount-orderid    = '000001000033'.   " 订单号
  APPEND lt_poaccount.

  CLEAR:lt_poaccountx.
  lt_poaccountx-po_item    = l_po_item.
  lt_poaccountx-po_itemx   = 'X'.
  lt_poaccountx-costcenter = 'X'.   " 成本中心
  lt_poaccountx-gl_account = 'X'.   " 总账科目
  lt_poaccountx-quantity   = 'X'.
  lt_poaccountx-asset_no   = 'X'.   " 固定资产编号
  lt_poaccountx-tax_code   = 'X'.   " 税码
  lt_poaccountx-orderid    = 'X'.   " 订单号
  APPEND lt_poaccountx.

*  itemtext     " 项目文本
  CLEAR:lt_potextitem.
  lt_potextitem-po_item = l_po_item.
  lt_potextitem-text_id = 'F01'.
  lt_potextitem-text_form = '*'.
  lt_potextitem-text_line = '测试项目'.     " 项目文本.
  APPEND lt_potextitem.

***交货信息
  CLEAR  lt_po_item_schedules.
  lt_po_item_schedules-po_item       = l_po_item.
  lt_po_item_schedules-quantity      = 11.
  lt_po_item_schedules-delivery_date = sy-datum.       " 交货日期
  APPEND lt_po_item_schedules.

  CLEAR  lt_schedulx.
  lt_schedulx-po_item   =  l_po_item.
  lt_schedulx-po_itemx  = 'X'.
  lt_schedulx-quantity  = 'X'.
  lt_schedulx-delivery_date = 'X'.
  APPEND lt_schedulx.

*ENDLOOP.

CALL FUNCTION 'BAPI_PO_CREATE1'
  EXPORTING
    poheader         = ls_po_header
    poheaderx        = ls_poheaderx
    poaddrvendor     = ls_poaddrvendor
  IMPORTING
    exppurchaseorder = lv_ebeln
  TABLES
    return           = lt_return
    poitem           = lt_po_items
    poitemx          = lt_itemx
    poschedule       = lt_po_item_schedules
    poschedulex      = lt_schedulx
    poaccount        = lt_poaccount
    poaccountx       = lt_poaccountx
    pocond           = lt_pocond
    pocondx          = lt_pocondx
    potextheader     = lt_potextheader
    potextitem       = lt_potextitem.


**** COMMIT WORK
READ TABLE lt_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.
*  CONCATENATE '采购订单' lv_ebeln '创建成功.'
*         INTO omessg.
*  MOVE '0' TO omsgno.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
*  LOOP AT lt_return WHERE type = 'E'.
*    MESSAGE ID lt_return-id TYPE lt_return-type NUMBER lt_return-number
*                            WITH lt_return-message_v1 lt_return-message_v2
*                                 lt_return-message_v3 lt_return-message_v4
*                         INTO l_temp.
*    CONCATENATE omessg l_temp INTO omessg SEPARATED BY ';'.
*  ENDLOOP.
*  MOVE '1' TO omsgno.
ENDIF.

WRITE:lv_ebeln.

其中我遇到一个问题

报了两个错

第一个科目 66012801 在科目表 ZOCA 中不存在

第二个 成本中心 1000/100101200 不存在

最后找到问题在于成本中心和 总账科目在 lt_poaccount, lt_po_items这两个参数要加前导零

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SAP BAPI_PO_CREATE1是一个SAP系统中的功能模块,用于创建采购订单(Purchase Order)。通过该功能模块,我们可以使用SAP系统来快速创建和维护采购订单的相关数据。 使用BAPI_PO_CREATE1,我们可以通过调用该功能模块来向SAP系统中创建新的采购订单。在调用该功能模块时,我们需要提供一些必要的输入参数,如采购订单的相关信息、采购组织和公司代码等。 这个功能模块可以帮助我们在SAP系统中自动化采购订单创建流程。它可以根据输入的参数,自动生成采购订单,并将相关的物料、供应商和价格等信息添加到订单中。 通过使用BAPI_PO_CREATE1,我们可以实现以下功能: 1. 创建采购订单:我们可以通过调用该功能模块来创建新的采购订单。在调用时,我们需要提供订单的相关信息,如供应商、物料、数量、交货日期等。系统会根据提供的信息自动创建采购订单。 2. 修改采购订单:除了创建新的采购订单,我们还可以使用BAPI_PO_CREATE1来修改现有的采购订单。在调用时,我们需要提供订单的标识符和要修改的字段及对应的值。系统将根据提供的信息来更新采购订单的数据。 3. 检查采购订单:在调用BAPI_PO_CREATE1之前,我们可以先使用BAPI_PO_EXISTENCE_CHECK来检查采购订单是否存在。这可以帮助我们避免重复创建订单或更新不存在的订单。 总而言之,SAP BAPI_PO_CREATE1是一个用于创建和维护采购订单的功能模块。它可以帮助我们在SAP系统中实现自动化的采购订单处理,并提高采购过程的效率和准确性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值