Skip to Content
0

BAPI to create Invoice(MIRO) for a contract (outline agreement)

Aug 16, 2017 at 07:58 PM

176

avatar image

Hi Gurus,

Any one can suggest which BAPI will work to create a Invoice against a contract(Outline Agreement).

I am using BAPI_INCOMINGINVOICE_CREATE , but its not working. But the same BAPI is working when I create invoice for Purchase order.

Its very urgent, thanks in advance.

Regards,

Ayyappan.V

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

ayyappan venugopal Aug 18, 2017 at 07:22 AM
0

Hi All,

I found a way to create an invoice for a contract using BAPI_INCOMINGINVOICE_CREATE.

There is no direct bapi available to create invoice for a contract, we have to enhance the std. bapi BAPI_INCOMINGINVOICE_CREATE.

Go inside the bapi and find the below Enhancement spot and create custom implementation for the same.

ENHANCEMENT-POINT BAPI_INCOMINGINVOICE_CREATE_02 SPOTS ES_SAPLMRM_BAPI.

Try modifying the TAB_DRSEG internal table by passing contract no and contract item, company code, vendor, plant as below.

ENHANCEMENT 1 ZAP_I126_CONTRACT_POSTING. "active version
*----------------------------------------------------------------------*
*Purpose: To create a invoice based on a contract. This Enhancment
*will be called only for specific FSD-> Contract related invoice creation
*scenario
*----------------------------------------------------------------------*

*Local Variable & Internal table Declaration
*----------------------------------------------------------------------*
DATA:
lv_ricefid TYPE char4,
lt_frseg LIKE tab_frseg.

*----------------------------------------------------------------------*
*Local Field Symbol Declaration
*----------------------------------------------------------------------*
FIELD-SYMBOLS:
<fs_cobl_mrm> TYPE cobl_mrm.

*----------------------------------------------------------------------*
*Local Constant Declaration
*----------------------------------------------------------------------*
CONSTANTS:
lc_i126 TYPE char20 VALUE 'I126_CONTRACT_INV',
lc_ricefid TYPE char20 VALUE 'RICEF_ID',
lc_c TYPE char1 VALUE 'C'.

*---Check whether the RICEF is I126 or not---*
SORT extensionin ASCENDING BY structure.
READ TABLE extensionin INTO DATA(lw_extensionin)
WITH KEY structure = lc_ricefid.
IF sy-subrc = 0.

IF lw_extensionin-valuepart1 = lc_i126.

IF tab_frseg IS NOT INITIAL.

*---Populating Contract details---*
LOOP AT tab_frseg INTO DATA(lw_frseg).

lw_frseg-erp_contract_id = lw_frseg-ebeln."Contract No
lw_frseg-erp_contract_itm = lw_frseg-ebelp."Contract Item
lw_frseg-ebeln = space.
lw_frseg-ebelp = space.
lw_frseg-xekbe = abap_true.
lw_frseg-lifnr = s_rbkpv-lifnr."Vendor
lw_frseg-koart = lc_c.

*Populate a logic to retrieve plant from lw_frseg-ebeln

lw_frseg-bwkey = 'OCPP'.

LOOP AT lw_frseg-cobl_mrm ASSIGNING <fs_cobl_mrm>.
<fs_cobl_mrm>-xunpl = abap_true.
<fs_cobl_mrm>-bukrs = s_rbkpv-bukrs.
ENDLOOP.

APPEND lw_frseg TO lt_frseg.
CLEAR: lw_frseg.
ENDLOOP.

REFRESH: tab_frseg.

*---Assigning back the modified values---*
tab_frseg = lt_frseg.

ENDIF.

ENDIF.

ENDIF.
ENDENHANCEMENT.


Sample program for creation of invoice for a contract.

DATA:lw_headerdata TYPE bapi_incinv_create_header,
lt_itemdata TYPE TABLE OF bapi_incinv_create_item,
lw_itemdata TYPE bapi_incinv_create_item,
lt_accountdata TYPE TABLE OF bapi_incinv_create_account,
lw_accountdata TYPE bapi_incinv_create_account,
lt_glaccount TYPE TABLE OF bapi_incinv_create_gl_account,
lw_glaccount TYPE bapi_incinv_create_gl_account,
lt_bapirettab TYPE bapirettab,
lv_invoicedocu LIKE bapi_incinv_fld-inv_doc_no,
lv_fyear LIKE bapi_incinv_fld-fisc_year,
lt_bapiret2 TYPE STANDARD TABLE OF bapiret2,
lt_extensionin TYPE TABLE OF bapiparex,
lw_extensionin TYPE bapiparex,
lw_i126_extn TYPE zst_i126_contractinvoice.

lw_headerdata-invoice_ind = abap_true.
lw_headerdata-doc_type = 'RE'.
lw_headerdata-doc_date = sy-datum.
lw_headerdata-pstng_date = sy-datum.
lw_headerdata-comp_code = 'XXXX'. "Pass relevant compcode
lw_headerdata-currency = 'USD'.
lw_headerdata-gross_amount = 5.
lw_headerdata-pmnttrms = 'B040'.
lw_headerdata-calc_tax_ind = abap_true.
lw_headerdata-header_txt = 'FSD-I126'.

*Item Details
lw_itemdata-invoice_doc_item = 1.
lw_itemdata-po_number = 4910000012.
lw_itemdata-po_item = 30.
*lw_itemdata-tax_code = 'EX'.
*lw_itemdata-taxjurcode = 'WI0010000'.
lw_itemdata-item_amount = 2.
lw_itemdata-po_unit = 'EA'.
lw_itemdata-quantity = 1.
APPEND lw_itemdata TO lt_itemdata.

lw_itemdata-invoice_doc_item = 2.
lw_itemdata-po_number = 4910000012.
lw_itemdata-po_item = 10.
*lw_itemdata-tax_code = 'EX'.
*lw_itemdata-taxjurcode = 'WI0010000'.
lw_itemdata-item_amount = 3.
lw_itemdata-po_unit = 'EA'.
lw_itemdata-quantity = 1.
APPEND lw_itemdata TO lt_itemdata.

*GL Account Details
lw_accountdata-invoice_doc_item = 1.
lw_accountdata-serial_no = 01.
lw_accountdata-taxjurcode = 'WI0010000'.
lw_accountdata-tax_code = 'EX'.
lw_accountdata-gl_account = '0713003000'.
lw_accountdata-quantity = 1.
lw_accountdata-po_unit = 'EA'.
lw_accountdata-item_amount = 2.
lw_accountdata-orderid = '001000000000'.
APPEND lw_accountdata TO lt_accountdata.

lw_accountdata-invoice_doc_item = 2.
lw_accountdata-serial_no = 02.
lw_accountdata-taxjurcode = 'WI0010000'.
lw_accountdata-tax_code = 'EX'.
lw_accountdata-gl_account = '0713003000'.
lw_accountdata-quantity = 1.
lw_accountdata-item_amount = 3.
lw_accountdata-orderid = '001000000000'.
APPEND lw_accountdata TO lt_accountdata.
*

lw_extensionin-structure = 'RICEF_ID'.
lw_extensionin-valuepart1 = 'XXXXXXXXX'.
APPEND lw_extensionin TO lt_extensionin.

CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
headerdata = lw_headerdata
IMPORTING
invoicedocnumber = lv_invoicedocu
fiscalyear = lv_fyear
TABLES
itemdata = lt_itemdata
accountingdata = lt_accountdata
glaccountdata = lt_glaccount
return = lt_bapiret2
extensionin = lt_extensionin.

BREAK-POINT.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

LOOP AT lt_bapiret2 INTO DATA(lw_ret2).
WRITE:/1 lw_ret2-number , 10 lw_ret2-id , 20 lw_ret2-message.
ENDLOOP.

WRITE:/ lv_invoicedocu.
WRITE:/ lv_fyear.

Share
10 |10000 characters needed characters left characters exceeded