2008 Jun 27 7:14 AM
Hi all,
Does anybody know the BAPI for posting MIRO after GR.
Pl send with sample example code to undestand better.
It is urgent.
Appreciated answeres will be rewarded.
Regards,
Venkatesh
09892 895847
2008 Jun 27 7:24 AM
Hi,
You may use FM BAPI_INCOMINGINVOICE_CREATE.
Regards
Raju Chitale
2008 Jun 27 7:20 AM
2008 Jun 27 7:24 AM
Hi,
You may use FM BAPI_INCOMINGINVOICE_CREATE.
Regards
Raju Chitale
2008 Jun 27 10:20 AM
Hi ,
Thanx for the answere.
Could you pls send me the sample code what values to be passed.
2008 Jul 01 8:28 AM
Check this code:
clear : it_itemdata, it_accountingdata, IT_CRMEMO_MIRO, IT_CRMEMO_MR8M.
refresh : it_itemdata, it_accountingdata, IT_CRMEMO_MIRO, IT_CRMEMO_MR8M.
*-- Copy all the CR Memo Docs and delete order reason not in S_AUGRU
IT_CRMEMO_MR8M[] = IT_CRMEMO[].
*-- Delete Reversal postings which are not in S_AUGRU
DELETE IT_CRMEMO_MR8M WHERE AUGRU IN S_AUGRU.
*-- Delete Reversal postings where AEDAT is initial
DELETE IT_CRMEMO_MR8M where aedat is initial.
*-- Delete order reason which are not in S_AUGRU
DELETE IT_CRMEMO WHERE AUGRU NOT IN S_AUGRU.
*-- Loop through the credit memo request records
LOOP AT IT_CRMEMO INTO WA_CRMEMO.
lv_tabix = sy-tabix.
*-- If credit memo request change date is not initial then
send change date (AEDAT) to lv_rbkp_bldat
if not WA_CRMEMO-aedat is initial.
lv_rbkp_bldat = WA_CRMEMO-aedat.
else.
*-- If credit memo request change date is initial then
send create date (ERDAT) to lv_rbkp_bldat
lv_rbkp_bldat = WA_CRMEMO-erdat.
endif.
READ TABLE IT_ORDERS INTO WA_ORDERS WITH KEY VBELN = WA_CRMEMO-VBELN
POSNN = WA_CRMEMO-POSNR.
IF SY-SUBRC = 0.
READ TABLE IT_PO INTO WA_PO WITH KEY VBELV = WA_ORDERS-VBELV
POSNV = WA_ORDERS-POSNV.
IF SY-SUBRC = 0.
READ TABLE IT_EKPO INTO WA_EKPO WITH KEY EBELN = WA_PO-VBELN
EBELP = WA_PO-POSNN.
IF SY-SUBRC = 0.
*-- Read IT_EKBE_TEMP internal table which contains records which are not reversed
READ TABLE IT_EKBE_TEMP INTO WA_EKBE_TEMP WITH KEY EBELN = WA_EKPO-EBELN
EBELP = WA_EKPO-EBELP.
IF SY-SUBRC = 0.
*-- Read IT_RBKP internal table with XRECH (Indicator: post invoice) = 'X' ,
check for invoice records for the correspnding CR Memo records
READ TABLE IT_RBKP INTO WA_RBKP WITH KEY BELNR = WA_EKBE_TEMP-BELNR
GJAHR = WA_EKBE_TEMP-GJAHR
XRECH = C_X.
IF SY-SUBRC = 0.
*-- Read IT_RBKP internal table with XRECH (Indicator: post invoice) = SPACE,
and document date = CR Memo creation date
and reference document number = PO number
READ TABLE IT_RBKP INTO WA_RBKP_TMP WITH KEY BELNR = WA_EKBE_TEMP-BELNR
GJAHR = WA_EKBE_TEMP-GJAHR
BLDAT = WA_CRMEMO-ERDAT
XRECH = ' '
XBLNR+0(10) = WA_EKBE_TEMP-ebeln.
STBLG = SPACE.
IF SY-SUBRC = 0.
CONTINUE.
ELSE.
*-- Quantity Conversion (Get the Credit Memo Quantity by passing CMR unit per one PO unit)
perform f_quantity_conv.
*-- Filling the Line items data
*-- Incrementing the item no
lv_itemno = lv_itemno + 1.
v_itemno = lv_itemno.
it_itemdata-invoice_doc_item = v_itemno.
it_itemdata-po_number = WA_ekPO-ebeln.
it_itemdata-po_item = WA_EKPO-EBELP.
it_itemdata-tax_code = WA_ekpo-mwskz.
it_itemdata-TAXJURCODE = WA_ekpo-TXJCD.
*-- Converting SAP amount to BAPI format by passing line item amount and currency
PERFORM f_currency_amount_sap_to_bapi USING WA_EKPO-waers
V_LINE_AMOUNT
CHANGING it_itemdata-item_amount .
it_itemdata-quantity = ( WA_CRMEMO-ZMENG * V_CRMEMO_QTY ).
it_itemdata-po_unit = WA_EKPO-MEINS.
APPEND it_itemdata.
*-- Populate Account Assignment data
IT_ACCOUNTINGDATA-INVOICE_DOC_ITEM = v_itemno.
IT_ACCOUNTINGDATA-XUNPL = space.
IT_ACCOUNTINGDATA-SERIAL_NO = C_01.
IT_ACCOUNTINGDATA-TAX_CODE = it_itemdata-tax_code.
IT_ACCOUNTINGDATA-TAXJURCODE = it_itemdata-TAXJURCODE.
IT_ACCOUNTINGDATA-ITEM_AMOUNT = it_itemdata-item_amount.
IT_ACCOUNTINGDATA-QUANTITY = it_itemdata-quantity.
IT_ACCOUNTINGDATA-PO_UNIT = it_itemdata-po_unit.
IT_ACCOUNTINGDATA-GL_ACCOUNT = C_0000500205.
append IT_ACCOUNTINGDATA.
clear IT_ACCOUNTINGDATA.
CLEAR it_itemdata.
endif.
endif.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
*-- At end of each credit memo request fill the header details of BAPI FM and
*-- post the BAPI
AT END OF VBELN.
read table it_crmemo into wa_crmemo index lv_tabix.
*-- Populate the document Header
*-- Getting the header data for invoice
x_docheader-invoice_ind = space.
x_docheader-doc_type = c_blart.
x_docheader-doc_date = lv_rbkp_bldat.
x_docheader-pstng_date = lv_rbkp_bldat.
x_docheader-ref_doc_no = WA_RBKP-XBLNR.
x_docheader-comp_code = WA_CRMEMO-BUKRS_VF.
x_docheader-CURRENCY = WA_CRMEMO-WAERK.
x_docheader-calc_tax_ind = lc_check.
*-- Logic to find the Tax %
v_tax_per = ( WA_RBKP-WMWST1 / ( WA_RBKP-RMWWR - WA_RBKP-WMWST1 ) ) * 100.
v_tax_amt = ( V_GROSSAMT * v_tax_per ) / 100.
V_GROSSAMT = ( V_GROSSAMT + v_tax_amt ).
x_docheader-gross_amount = V_GROSSAMT.
CLEAR:v_docnr, v_year1.
*-- Calling BAPI to create PO invoice document
CHECK NOT IT_ITEMDATA[] IS INITIAL.
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
headerdata = x_docheader
IMPORTING
invoicedocnumber = v_docnr
fiscalyear = v_year1
TABLES
itemdata = it_itemdata[]
ACCOUNTingDATA = it_ACCOUNTingDATA[]
GLACCOUNTDATA =
taxdata =
return = it_return.
*-- Commit work
IF NOT v_docnr IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
*-- Move the data to Success Internal Table
wa_success-crmemo = wa_crmemo-vbeln.
wa_success-cmemo = wa_cmemo-vbeln.
wa_success-orders = wa_orders-vbelv.
wa_success-po = wa_po-vbeln.
wa_success-miro_no = v_docnr.
wa_success-text = 'MIRO is Posted'.
append wa_success TO it_success.
clear wa_success.
ENDIF.
*-- Read the values in the table IT_RETURN.
CLEAR it_return.
READ TABLE it_return INDEX 1.
If message type is error then roll back the work
IF it_return-type = C_E.
*-- Roll back
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
*-- Move the data to Error Internal Table
wa_error-crmemo = wa_crmemo-vbeln.
wa_error-cmemo = wa_cmemo-vbeln.
wa_error-orders = wa_orders-vbelv.
wa_error-po = wa_po-vbeln.
wa_error-text = it_return-MESSAGE.
append wa_error TO it_error.
clear wa_error.
ENDIF.
refresh: it_return, it_itemdata, it_accountingdata.
clear: V_GROSSAMT, it_return, it_itemdata, wa_crmemo, wa_orders, wa_po,
wa_ekpo, WA_EKBE_TEMP, wa_rbkp, wa_rbkp_tmp, v_docnr, v_year1, WA_SUCCESS,
WA_ERROR, it_accountingdata, v_tax_per, v_tax_amt, V_FILL_ITEM, lv_rbkp_bldat.
ENDAT.
ENDLOOP.
cheers
Aveek
2008 Jul 01 8:34 AM
Venka,
FM: BAPI_INCOMINGINVOICE_CREATE
Make sure header field INVOICE_IND is set accordingly.
Sub debit set to X
Sub credit set to blank
Then on the item data, the field DE_CRE_IND, set the field to X for Sub Debit and blank for Sub Debit.
Amit.
2011 May 15 9:11 AM