前面我们讲了FB01/F/02 会计凭证的创建和FB08会计凭证的冲销bapi。以及事务代码TCODE:VF11发票冲销的BAPI
今天,趁着做核酸做得喉咙起茧想要休息一下,我们来一起温故学习一下发票创建的BAPI。
SD顾问前台常用的事务代码是VF01或者VF04。
BAPI_BILLINGDOC_CREATEMULTIPLE
这个BAPI函数属于SD模块,是SAP ABAP Constant beginners 在tutorial 中的基本内容。
是一个常用的BAPI,导入的参数有:
参数名称 | 关联类型 | 可选的 | 说明 |
CREATORDATAIN | BAPICREATORDATA | 可选 | 有关设置数据源的信息 |
TESTRUN | BAPIVBRKTESTRUN-TESTRUN | 可选 | 是否测试运行 |
POSTING | POSTING_TYPE_CT | 可选 | 记帐种类: 直接记帐 |
而她的表对象有如下:
参数名称 | 关联类型 | 可选的 | 说明 |
BILLINGDATAIN | BAPIVBRK | 必选 | 开票标题字段 |
ERRORS | BAPIVBRKERRORS | 可选 | 项目错误处理的信息 |
SUCCESS | BAPIVBRKSUCCESS | 必选 | 成功处理记帐凭证项目的信息 |
RETURN | BAPIRET1 | 必选 | 返回参数 |
在我们的日常项目中,一般会这样编写测试demo代码。
DATA: lt_billingdatain TYPE TABLE OF bapivbrk,
ls_billingdatain TYPE bapivbrk,
lt_success TYPE TABLE OF bapivbrksuccess,
ls_success TYPE bapivbrksuccess,
lt_return TYPE TABLE OF bapiret1,
ls_return TYPE bapiret1.
DATA: lt_din_item TYPE TABLE OF zifrmx_datain_013p01-item,
ls_din_item TYPE LINE OF zifrmx_datain_013p01-item,
* lt_din_cond TYPE TABLE OF zifrmx_datain_013p01-conds,
* ls_din_cond TYPE LINE OF zifrmx_datain_013p01-conds,
lt_dou_item TYPE TABLE OF zifrmx_dataout_013p01-item,
ls_dou_item TYPE LINE OF zifrmx_dataout_013p01-item,
ls_msg TYPE zifsret01,
lv_fkart TYPE vbrk-fkart VALUE ‘ZR1’,
lv_vbtyp TYPE vbrk-vbtyp VALUE ‘C’,
lv_index TYPE i.
CLEAR: lv_index.
* BAPI赋值
LOOP AT tp_din_item INTO ls_din_item.
lv_index = lv_index + 1.
ls_billingdatain-doc_number = ls_din_item-vbeln.
ls_billingdatain-itm_number = ls_din_item-posnr.
ls_billingdatain-ref_doc = ls_din_item-vbeln.
ls_billingdatain-ref_item = ls_din_item-posnr.
ls_billingdatain-ordbilltyp = lv_fkart.
ls_billingdatain-ref_doc_ca = lv_vbtyp.
ls_billingdatain-salesorg = ls_din_item-vkorg.
ls_billingdatain-distr_chan = ls_din_item-vtweg.
ls_billingdatain-division = ls_din_item-spart.
ls_billingdatain-sold_to = ls_din_item-kunnr_ag. “售达方
ls_billingdatain-ship_to = ls_din_item-kunnr_we. “送达方
ls_billingdatain-bill_to = ls_din_item-kunnr_re. “开票方
ls_billingdatain-payer = ls_din_item-kunnr_rg. “付款方
ls_billingdatain-payment_terms = ls_din_item-zterm.
ls_billingdatain-incoterms1 = ls_din_item-inco1.
ls_billingdatain-incoterms2 = ls_din_item-inco2.
ls_billingdatain-plant = ls_din_item-werks.
ls_billingdatain-material = ls_din_item-matnr.
ls_billingdatain-req_qty = ls_din_item-menge.
ls_billingdatain-sales_unit = ls_din_item-meins.
APPEND ls_billingdatain TO lt_billingdatain.
CLEAR: ls_billingdatain.
ENDLOOP.
CALL FUNCTION ‘BAPI_BILLINGDOC_CREATEMULTIPLE’
TABLES
billingdatain = lt_billingdatain
return = lt_return
success = lt_success
.
IF lt_success IS INITIAL.
cp_eind = ‘X’.
ENDIF.
IF cp_eind EQ ‘X’.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.
“返回成功的发票号
LOOP AT lt_success INTO ls_success.
CLEAR: ls_dou_item.
ls_dou_item-vbeln = ls_success-bill_doc.
ls_dou_item-posnr = ls_success-bill_doc_item.
APPEND ls_dou_item TO tp_dou_item.
cp_vbeln = ls_success-bill_doc.
ENDLOOP.
ENDIF.
LOOP AT lt_return INTO ls_return.
ls_msg-class = ‘BUS’.
ls_msg-msgtyp = ls_return-type.
ls_msg-msgno = ls_return-number.
ls_msg-msgtxt = ls_return-message.
APPEND ls_msg TO tp_msg.
CLEAR ls_msg.
ENDLOOP.
请问您学会了吗?
作者致力于SAP ABAP Constant tutorial for beginners ,希望信息化越来越美好~
本文链接 : http://www.hot583.com/2022/03/30/bapi_billingdoc_createmultiple/
本文为作者原创,如果这篇文章对您有用,欢迎转载,
转载请务必注明来源《今日热点在看》http://www.hot583.com/
我的微信公众号【hot583】 或者在这个链接联系我
微信原文《全文完》