Bapi: bapi_incominginvoice_park (tcode: mir7-premade supplier invoice)

Source: Internet
Author: User

*&---------------------------------------------------------------------*
* & Form frm_incominginvoice_park
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> P_lt_poitem text
* --> P_lt_baitem text
* --> P_lt_taitem text
* --> P_lt_msg text
* --> P_ls_head text
* <-- P_lv_eind text
*----------------------------------------------------------------------*
Form Frm_incominginvoice_park Tables Tp_poitemStructure Zrmxmms013
Tp_baitem Structure Zrmxmms014
Tp_taitem Structure Zrmxmms015
Tp_msg Structure Zifsret01
Using Sp_head Like Zrmxmms012
Sp_ifdataout Like Zifrmx_dataout_007p01
Changing Vp_eind.

 

Data: lt_poitem Type Zifrmx_datain_007p01-po_item,
Ls_poitemType Line Of Zifrmx_datain_007p01-po_item,
Lt_baitem Type Zifrmx_datain_007p01-ba_item,
Ls_baitem Type Line Of Zifrmx_datain_007p01-ba_item,
Lt_taitem Type Zifrmx_datain_007p01-ta_item,
Ls_taitem Type Line Of Zifrmx_datain_007p01-ta_item,
Ls_msg Type Zifsret01,

Ls_headerdata Like Bapi_incinv_create_header,
Lt_itemdata Like Table Of Bapi_incinv_create_item,
Ls_itemdata Like Bapi_incinv_create_item,
Lt_materialdata Like Table Of Bapi_incinv_create_material,
Ls_materialdata Like Bapi_incinv_create_material,
Lt_taxdata Like Table Of Bapi_incinv_create_tax,
Ls_taxdata Like Bapi_incinv_create_tax,
Lt_return Like Table Of Bapiret2,
Ls_return Like Bapiret2,
Lv_invoicedocnumber Like Bapi_incinv_fld-inv_doc_no,
Lv_fiscalyear Like Bapi_incinv_fld-fisc_year.

* 1/3 invoice_ind = 'X' db_cr_ind = 'S' (header), 2/4 invoice_ind = ''db_cr_ind = 'H' (external item)
* 1/2 de_cre_ind = '', 3/4 de_cre_ind = 'X' (PO procurement order related project)

* Bapi assignment
Ls_headerdata-invoice_ind = sp_head-xrech. "Invoice mark
Ls_headerdata-doc_type = sp_head-blart.
Ls_headerdata-doc_date = sp_head-bldat.
Ls_headerdata-pstng_date = sp_head-budat.
Ls_headerdata-bline_date = sp_head-zfbdt. "Baseline date/payment calculation start date
Ls_headerdata-comp_code = sp_head-bukrs.
Ls_headerdata-currency = sp_head-waers.
Ls_headerdata-gross_amount = sp_head-rmwwr. "Total Amount
Ls_headerdata-del_costs = sp_head-beznk. "Unplanned delivery fee
Ls_headerdata-pmnttrms = sp_head-zterm. "Payment conditions
Ls_headerdata-alloc_nmbr = sp_head-zuonr. "Allocation No./external invoice No.
Ls_headerdata-diff_inv = sp_head-lifnr. "Invoice party/Supplier
Ls_headerdata-ref_doc_no = sp_head-xblnr.
Ls_headerdata-header_txt = sp_head-bktxt.
Ls_headerdata-item_text = sp_head-sgtxt.

Loop At Tp_poitem Into Ls_poitem.
Ls_itemdata-invoice_doc_item = ls_poitem-buzei. "Invoice line project No.
Ls_itemdata-po_number = ls_poitem-ebeln.
Ls_itemdata-po_item = ls_poitem-ebelp.
Ls_itemdata-ref_doc = ls_poitem-lfbnr.
Ls_itemdata-ref_doc_year = ls_poitem-lfgja.
Ls_itemdata-ref_doc_it = ls_poitem-lfpos.
Ls_itemdata-item_amount = ls_poitem-wrbtr.
Ls_itemdata-quantity = ls_poitem-menge.
Ls_itemdata-po_unit = ls_poitem-meins.
Ls_itemdata-tax_code = ls_poitem-mwskz.
Ls_itemdata-de_cre_ind = ls_poitem-tbtkz. "Logo: Post-renewal/Loan
Ls_itemdata-cond_type = ls_poitem-kschl. "Condition Type
Ls_itemdata-freight_ven = ls_poitem-lifnr. "Supplier or creditor's account
Append Ls_itemdata To Lt_itemdata.
Clear: ls_itemdata.
Endloop.

Loop At Tp_baitem Into Ls_baitem.
Ls_materialdata-invoice_doc_item = ls_baitem-buzei.
Ls_materialdata-material = ls_baitem-matnr.
Ls_materialdata-val_area = ls_baitem-bwkey."Evaluation scope/factory
Ls_materialdata-valuation_type = ls_baitem-bwtar. "Evaluation type
Ls_materialdata-db_cr_ind = ls_baitem-shkzg. "Debit/credit ID
Ls_materialdata-item_amount = ls_baitem-wrbtr.
Ls_materialdata-quantity = ls_baitem-menge.
Ls_materialdata-base_uom = ls_baitem-meins.
Ls_materialdata-tax_code = ls_baitem-mwskz.
Append Ls_materialdata To Lt_materialdata.
Clear: ls_materialdata.
Endloop.

LoopAtTp_taitemIntoLs_taitem.
Ls_taxdata-tax_code = ls_taitem-mwskz.
Ls_taxdata-tax_amount = ls_taitem-wrbtr.
AppendLs_taxdataToLt_taxdata.
Clear: ls_taxdata.
Endloop.

Call Function 'Bapi _ incominginvoice_park'
Exporting
Headerdata = ls_headerdata
* Addressdata =
Importing
Invoicedocnumber = lv_invoicedocnumber
Fiscalyear = lv_fiscalyear
Tables
Itemdata = lt_itemdata
* Accountingdata =
* Glaccountdata =
Materialdata = lt_materialdata
Taxdata = lt_taxdata
* Withtaxdata =
* Vendoritemsplitdata =
Return = Lt_return
.

IfLv_invoicedocnumberIsInitialOrLv_fiscalyearIsInitial.
Vp_eind ='X'.
Endif.

IfVp_eind ='X'.
CallFunction'Bapi _ transaction_rollback'.

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.

Else.
CallFunction'Bapi _ transaction_commit'
Exporting
Wait='X'.

Sp_ifdataout-eblnr = lv_invoicedocnumber.
Sp_ifdataout-gjahr = lv_fiscalyear.

Endif.

Endform."Frm_incominginvoice_park

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.