1、事务代码MIR7
前台输入采购订单等相关字段进行开票
2、代码实现
调用BAPI:BAPI_INCOMINGINVOICE_PARK创建发票
"--------------------@斌将军--------------------
DATA:ls_headerdata TYPE bapi_incinv_create_header,
lv_invoicedocnumber LIKE bapi_incinv_fld-inv_doc_no,
lv_fiscalyear LIKE bapi_incinv_fld-fisc_year,
lt_itemdata TYPE STANDARD TABLE OF bapi_incinv_create_item,
ls_itemdata TYPE bapi_incinv_create_item,
lt_taxdata LIKE TABLE OF bapi_incinv_create_tax,
ls_taxdata LIKE bapi_incinv_create_tax,
lt_return TYPE STANDARD TABLE OF bapiret2,
ls_return TYPE bapiret2.
DATA:lv_item TYPE bapi_incinv_create_item-invoice_doc_item,
lv_check TYPE char1,
lv_message TYPE char200.
CLEAR:ls_headerdata.
ls_headerdata-invoice_ind = 'X'. "标识: 记帐发票
ls_headerdata-doc_type = 'RE'."凭证类型
ls_headerdata-doc_date = sy-datum."凭证中的凭证日期
ls_headerdata-pstng_date = sy-datum."凭证中的过账日期
ls_headerdata-comp_code = '1010'."公司代码
ls_headerdata-currency = 'CNY'."货币码
ls_headerdata-bline_date = sy-datum."用于到期日计算的基准日期
CLEAR ls_itemdata.
lv_item = lv_item + 1.
ls_itemdata-invoice_doc_item = lv_item."发票凭证中的凭证项目
ls_itemdata-po_number = '4600000075'."采购凭证号
ls_itemdata-po_item = '20'."采购凭证的项目编号
ls_itemdata-item_amount = '50'."凭证货币金额
ls_itemdata-quantity = '5'."数量
ls_itemdata-po_unit = 'EA'."订单单位
ls_itemdata-tax_code = 'J1'."销售/购买税代码
ls_itemdata-ref_doc = '5000001650'."参考凭证号
ls_itemdata-ref_doc_it = '3'."发票凭证中的凭证项目
ls_itemdata-ref_doc_year = '2022'."会计年度
APPEND ls_itemdata TO lt_itemdata.
CLEAR:ls_taxdata.
ls_taxdata-tax_code = 'J1'.
ls_taxdata-tax_amount = '8'.
APPEND ls_taxdata TO lt_taxdata.
CALL FUNCTION 'BAPI_INCOMINGINVOICE_PARK'
EXPORTING
headerdata = ls_headerdata
IMPORTING
invoicedocnumber = lv_invoicedocnumber
fiscalyear = lv_fiscalyear
TABLES
itemdata = lt_itemdata
taxdata = lt_taxdata
return = lt_return.
CLEAR:lv_check,lv_message.
LOOP AT lt_return INTO ls_return WHERE type CA 'AEX'.
lv_check = 'E'.
lv_message = lv_message && ls_return-message.
ENDLOOP.
IF lv_check = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
"--------------------@斌将军--------------------
MIR7有四种处理业务,传值稍有不同
1.发票:
HEADERDATA-INVOICE_IND = 'X'.
TEMDATA-DE-CRE_IND = ''.
2.贷项凭证:
HEADERDATA-INVOICE_IND = ''.
TEMDATA-DE-CRE_IND = ''.
3.后续借记:
HEADERDATA-INVOICE_IND = 'X'.
TEMDATA-DE-CRE_IND = 'X'.
4.后续贷记:
HEADERDATA-INVOICE_IND = ''.
TEMDATA-DE-CRE_IND = 'X'.
标签:BAPI,凭证,itemdata,lv,item,ls,预制,MIR7,headerdata From: https://blog.51cto.com/BinGeneral/5901211