*&---------------------------------------------------------------------*
*& 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这两个参数要加前导零