Monday, July 14, 2008

Create MIRO with GL reference and Profitability segment using BAPI

Purpose : Create MIRO with GL reference and Profitability segment using BAPI.
Function Module : BAPI_INCOMINGINVOICE_CREATE

Field used :
*** HEADERDATA – 1 row
MIRO_HEADER-INVOICE_IND = 'X'.
MIRO_HEADER-DOC_TYPE = 'RE'.
MIRO_HEADER-DOC_DATE =
MIRO_HEADER-PSTNG_DATE = SY-DATUM.
MIRO_HEADER-REF_DOC_NO = [ reference PO number from that GR ]
MIRO_HEADER-PO_REF_NO = [ dummy PO – all item deleted ]
MIRO_HEADER-COMP_CODE = [ company code ]
MIRO_HEADER-DIFF_INV = [ vendor code ]
MIRO_HEADER-BUS_AREA = [ business area ]
MIRO_HEADER-CURRENCY = [ currency used on MIRO doc ]
MIRO_HEADER-EXCH_RATE = 1.
MIRO_HEADER-ALLOC_NMBR = [ allocation number, on my case I use same number with ref_doc_no ]
MIRO_HEADER-HEADER_TXT = [header text]


*** TAXDATA – 1 row
MIRO_HEADER-ITEM_TEXT = [header text]
MIRO_TAX-TAX_CODE = [tax code]

*** MATERIALDATA – 1 row [in my case I use only 1 material]
MIRO_MAT-INVOICE_DOC_ITEM = [sequence number]
MIRO_MAT-MATERIAL = [material number]
MIRO_MAT-VAL_AREA = [plant]
MIRO_MAT-DB_CR_IND = 'S'.
MIRO_MAT-ITEM_AMOUNT = [value amount]
MIRO_MAT-QUANTITY = [value quantity]
MIRO_MAT-BASE_UOM = [unit]
MIRO_MAT-BASE_UOM_ISO = [unit]
MIRO_MAT-TAX_CODE = [tax code]

*** GLACCOUNTDATA – multiple row, according to GL account related to journal
MIRO_GL-INVOICE_DOC_ITEM = [line number - sequence]
MIRO_GL-GL_ACCOUNT = [GL account]
MIRO_GL-ITEM_AMOUNT = [GL value amount]
MIRO_GL-DB_CR_IND = 'H'.
MIRO_GL-COMP_CODE = [company code]
MIRO_GL-TAX_CODE = [tax code]
MIRO_GL-BUS_area = [business area]

*** RUN THE BAPI
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
HEADERDATA = miro_header
IMPORTING
INVOICEDOCNUMBER = result_invoice
FISCALYEAR = result_invoice_year
TABLES
ITEMDATA = miro_item
TAXDATA = miro_tax
GLACCOUNTDATA = miro_gl
MATERIALDATA = miro_mat
RETURN = return.

*** INVOICE NUMBER
RESULT_INVOICE
RESULT_INVOICE_YEAR

*** YOU NEED TO COMMIT THE TRANSACTION, OTHERWISE THE INVOICE NUMBER WONT BE SAVED COMPLETELY

IF RESULT_INVOICE NE SPACE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.

No comments: