Create incoming vendor invoice (MIRO) using BAPI BAPI_INCOMINGINVOICE_CREATE.
*&---------------------------------------------------------------------*
*& Report ZSW_BAPI_INC_INV_CREATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSW_BAPI_INC_INV_CREATE.
DATA: wa_header LIKE bapi_incinv_create_header.
DATA: it_item TYPE STANDARD TABLE OF bapi_incinv_create_item,
wa_item TYPE bapi_incinv_create_item.
DATA: it_ret LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: g_invno LIKE bapi_incinv_fld-inv_doc_no,
g_fyear LIKE bapi_incinv_fld-fisc_year.
********************************************
****<<<<<<<<<<<<DATA DECLARE>>>>>>>>>>>>****
********************************************
wa_header-invoice_ind = 'X'.
wa_header-doc_date = '20120131'. "Document date
wa_header-pstng_date = '20120201'. "Posting date
wa_header-ref_doc_no = 'Test'. "Ref doc. No.
wa_header-comp_code = '3101'. "Company Code
wa_header-gross_amount = '5908.11'. "Gross amount(aft. tax) for the invoice
wa_header-calc_tax_ind = 'X'.
wa_header-currency = 'USD'. "Currency Field
wa_item-invoice_doc_item = '000011'.
wa_item-po_number = '4590038151'. "PO number
wa_item-po_item = '00121'. "PO item number
wa_item-ref_doc = '5007548571'. "GR number
wa_item-ref_doc_year = '2018'. "GR fiscal year
wa_item-ref_doc_it = '0011'. "GR item number
wa_item-tax_code = 'V7'. "Tax code applicable
wa_item-item_amount = '5521.61'. "Item amount
wa_item-quantity = '3381'. "Invoice quantity
wa_item-po_unit = 'EA'. "UoM
APPEND wa_item TO it_item.
*********************************************************
*<<<<<<<<<CALL BAPI fOR INCOMINGINVOICE_CREATE>>>>>>>>>>*
*********************************************************
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
headerdata = wa_header
* ADDRESSDATA =
IMPORTING
invoicedocnumber = g_invno
fiscalyear = g_fyear
TABLES
itemdata = it_item
* ACCOUNTINGDATA =
* GLACCOUNTDATA =
* MATERIALDATA =
* TAXDATA =
* WITHTAXDATA =
* VENDORITEMSPLITDATA =
return = it_ret
* EXTENSIONIN =
.
*********************************************************
******<<<<<<<<<<<<Bapi Commit section start.>>>>>>>>>>***
*********************************************************
IF g_invno IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.
ENDIF.
*********************************************************
******<<<<<<<<<<<<Bapi Commit section End.>>>>>>>>>>***
*********************************************************
WRITE:/1 g_invno, g_fyear.
LOOP AT it_ret.
WRITE:/1 it_ret-message.
ENDLOOP.
*****************<<<<<<<<<<<<END>>>>>>>>>>>>*************
*&---------------------------------------------------------------------*
*& Report ZSW_BAPI_INC_INV_CREATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSW_BAPI_INC_INV_CREATE.
DATA: wa_header LIKE bapi_incinv_create_header.
DATA: it_item TYPE STANDARD TABLE OF bapi_incinv_create_item,
wa_item TYPE bapi_incinv_create_item.
DATA: it_ret LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: g_invno LIKE bapi_incinv_fld-inv_doc_no,
g_fyear LIKE bapi_incinv_fld-fisc_year.
********************************************
****<<<<<<<<<<<<DATA DECLARE>>>>>>>>>>>>****
********************************************
wa_header-invoice_ind = 'X'.
wa_header-doc_date = '20120131'. "Document date
wa_header-pstng_date = '20120201'. "Posting date
wa_header-ref_doc_no = 'Test'. "Ref doc. No.
wa_header-comp_code = '3101'. "Company Code
wa_header-gross_amount = '5908.11'. "Gross amount(aft. tax) for the invoice
wa_header-calc_tax_ind = 'X'.
wa_header-currency = 'USD'. "Currency Field
wa_item-invoice_doc_item = '000011'.
wa_item-po_number = '4590038151'. "PO number
wa_item-po_item = '00121'. "PO item number
wa_item-ref_doc = '5007548571'. "GR number
wa_item-ref_doc_year = '2018'. "GR fiscal year
wa_item-ref_doc_it = '0011'. "GR item number
wa_item-tax_code = 'V7'. "Tax code applicable
wa_item-item_amount = '5521.61'. "Item amount
wa_item-quantity = '3381'. "Invoice quantity
wa_item-po_unit = 'EA'. "UoM
APPEND wa_item TO it_item.
*********************************************************
*<<<<<<<<<CALL BAPI fOR INCOMINGINVOICE_CREATE>>>>>>>>>>*
*********************************************************
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
headerdata = wa_header
* ADDRESSDATA =
IMPORTING
invoicedocnumber = g_invno
fiscalyear = g_fyear
TABLES
itemdata = it_item
* ACCOUNTINGDATA =
* GLACCOUNTDATA =
* MATERIALDATA =
* TAXDATA =
* WITHTAXDATA =
* VENDORITEMSPLITDATA =
return = it_ret
* EXTENSIONIN =
.
*********************************************************
******<<<<<<<<<<<<Bapi Commit section start.>>>>>>>>>>***
*********************************************************
IF g_invno IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.
ENDIF.
*********************************************************
******<<<<<<<<<<<<Bapi Commit section End.>>>>>>>>>>***
*********************************************************
WRITE:/1 g_invno, g_fyear.
LOOP AT it_ret.
WRITE:/1 it_ret-message.
ENDLOOP.
*****************<<<<<<<<<<<<END>>>>>>>>>>>>*************