Posted: Sun Oct 14, 2007 9:19 pm Post subject: Posting Vendor Invoices using 'BAPI_INCOMINGINVOICE_CREATE'
Requirement:
Invoice data is sent by the vendors in a text file and an inbound interface is required to create Vendor Invoices in SAP. The file contains the Purchase Order information, material quantity received from vendor along with the amount. Here the requirement becomes a little complex as there might be several occurrences of same Purchase Order item in one invoice.
Processing:
After reading data from the text File, it will be converted into Invoice header and item internal tables as required in the BAPI. Since there is a chance of multiple occurrence of same Purchase Order item in one Invoice, accounting data table is also required to be populated. It means accounting data table will have to have unplanned account assignments for re-appearing PO lines. Otherwise, the BAPI will encounter problems at runtime and a dump will be generated while trying to insert a duplicate row in table EKKN. Check OSS Note 518338. Further, BAPI 'BAPI_INCOMINGINVOICE_CREATE' is called to create Invoice. Here, populating internal tables for simple cases is fairly easy so code below will concentrate on populating accounting data for re-appearing Puchase Order items.
Code:
REPORT Z_BAPI_INCOMINGINVOICE_CREATE .
*----------------------------------------------------------------------*
* Create Vendor Invoices using BAPI - Date - 14.05.2005
*----------------------------------------------------------------------*
* Written By: Ram Manohar Tiwari
*----------------------------------------------------------------------*
* Presented By: http://www.rmtiwari.com
*----------------------------------------------------------------------*
* Invoice data is sent by the vendors in a text file and an inbound
* interface is required to create Vendor Invoices in SAP.
* The file contains the Purchase Order information, material quantity
* received from vendor along with the amount.
* Here the requirement becomes a little complex as there might be
* several ocuurences of same Purchase Order item in one invoice.
*----------------------------------------------------------------------*
* Only a incomplete sample coding is given here and it can only be used
* as a base for writing a program.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Populate internal Table I_ITAB from the data uploaded
* from text data file.
*......
*......
*----------------------------------------------------------------------*
* Populate Item Table from item data in data file
*......
*......
* Processing for header records of data file.
* set up header data for BAPI call.
* Check whwther it's an Incoice or Credit Memo.
* And populate Invoice indicator accordingly.
* Populate quantities if not a blanket order
IF I_ITAB-BLANKET EQ SPACE.
I_ITEM-QUANTITY = I_ITAB-MENGE.
PERFORM GET_MEINS USING I_ITAB-EBELN " Use table EKPO
I_ITAB-EBELP
CHANGING I_ITEM-PO_UNIT.
I_ACCOUNTINGDATA-PO_UNIT = I_ITEM-PO_UNIT.
IF I_ITEM-QUANTITY EQ 0.
I_ITEM-PO_UNIT = SPACE.
ENDIF.
ENDIF.
* Item Text
I_ITEM-ITEM_TEXT = I_ITAB-ITEM_TEXT.
APPEND I_ITEM.
* Populate Accounting Data
IF I_ITAB-BLANKET EQ SPACE.
I_ACCOUNTINGDATA-INVOICE_DOC_ITEM = lv_COUNT.
I_ACCOUNTINGDATA-SERIAL_NO = '01'.
* The following coding is to solve the problem
* mentioned in OSS Note 518338.
* Same PO item within several invoice items.
SORT I_ITEM BY PO_NUMBER PO_ITEM.
LOOP AT I_ITEM.
ON CHANGE OF I_ITEM-PO_NUMBER OR I_ITEM-PO_ITEM.
W_COUNTER = 1.
LOOP AT I_ITEM WHERE PO_NUMBER = I_ITEM-PO_NUMBER
AND PO_ITEM = I_ITEM-PO_ITEM.
* To solve the repetition of PO item in subsequent invoices.
ELSEIF SY-TABIX EQ 1.
W_COUNTER = 1.
LOOP AT I_ITEM WHERE PO_NUMBER = I_ITEM-PO_NUMBER
AND PO_ITEM = I_ITEM-PO_ITEM.
Example for the correct filling of the interface parameters for function module BAPI_INCOMINGINVOICE_CREATE:
You receive an invoice with reference to purchase order number 4500000191, purchase order item 10. The system calculates two services A and B with a quantity of six service units each. Service A has a gross amount of 580 euro including 16 % value-added tax. For service B, the system calculates 812 euro including 16 % value-added tax. 50 % of service A was assigned in each case to the two cost centers 1000 and 2000, similarly 50 % of service B was also assigned in each case to cost centers 1000 and 3000. The acceptance of services performed is only executed for the two services together with service entry sheet no. 1000000022.
For this, enter the following data:
Table HEADERDATA
INVOICE_IND (Post invoice/credit memo): X
DOC_TYPE (Document type): RE
DOC_DATE (Document date): 01/10/2002
PSTNG_DATE (Posting date): 01/10/2002
COMP_CODE (Company code): 0001
CURRENCY (Currency key): EUR
GROSS_AMOUNT (Gross amount): 1392,00
CALC_TAX_IND (Automatically Calculate Tax): X
PMNTTRMS (Terms of payment key): 0001
Table ITEMDATA
First entry for service A:
INVOICE_DOC_ITEM (Item of invoice document): 000001
PO_NUMBER (Purchase order number): 4500000191
PO_ITEM (Purchase order item): 00010
TAX_CODE (Tax code): V1
ITEM_AMOUNT (Item amount): 250.00
QUANTITY (Quantity): 3
PO_UNIT (Unit of measure): LE
SHEET_NO (Entry sheet number): 1000000022
SHEET_ITEM (Line number) : 10
Second entry for service A:
INVOICE_DOC_ITEM (Item of invoice document): 000002
PO_NUMBER (Purchase order number): 4500000191
PO_ITEM (Purchase order item): 00010
TAX_CODE (Tax code): V1
ITEM_AMOUNT (Item amount): 250.00
QUANTITY (Quantity): 3
PO_UNIT (Unit of measure): LE
SHEET_NO (Entry sheet number): 1000000022
SHEET_ITEM (Line number): 10
First entry for service B:
INVOICE_DOC_ITEM (Item of invoice document): 000003
PO_NUMBER (Purchase order number): 4500000191
PO_ITEM (Purchase order item): 00010
TAX_CODE (Tax code): V1
ITEM_AMOUNT (Item amount): 350.00
QUANTITY (Quantity): 3
PO_UNIT (Unit of measure): LE
SHEET_NO (Entry sheet number): 1000000022
SHEET_ITEM (Line number) : 20
Second entry for service B:
INVOICE_DOC_ITEM (Item of invoice document): 000004
PO_NUMBER (Purchase order number): 4500000191
PO_ITEM (Purchase order item): 00010
TAX_CODE (Tax code): V1
ITEM_AMOUNT (Item amount): 350,00
QUANTITY (Quantity): 3
PO_UNIT (Unit of measure): LE
SHEET_NO (Entry sheet number): 1000000022
SHEET_ITEM (Line number) : 20
Table ACCOUNTINGDATA
First account assignment for service A:
INVOICE_DOC_ITEM (Document item in invoice document): 000001
SERIAL_NO (Serial number of account assignment): 01
TAX_CODE (Tax code): V1
ITEM_AMOUNT (Amount in document currency): 250.00
QUANTITY (Quantity): 3
PO_UNIT (Order unit): LE
GL_ACCOUNT (Number of G/L account): 400000
COSTCENTER (Cost center): 1000
Second account assignment for service A:
INVOICE_DOC_ITEM (Document item in invoice document): 000002
SERIAL_NO (Serial number of account assignment): 02
TAX_CODE (Tax code): V1
ITEM_AMOUNT (Amount in document currency): 250.00
QUANTITY (Quantity): 3
PO_UNIT (Order unit): LE
GL_ACCOUNT (Number of G/L account): 400000
COSTCENTER (Cost center): 2000
First account assignment for service B:
INVOICE_DOC_ITEM (Document item in invoice document): 000003
SERIAL_NO (Serial number of account assignment): 01
TAX_CODE (Tax code): V1
ITEM_AMOUNT (Amount in document currency): 350.00
QUANTITY (Quantity): 3
PO_UNIT (Order unit): LE
GL_ACCOUNT (Number of G/L account): 400000
COSTCENTER (Cost center): 1000
Second account assignment for service B:
INVOICE_DOC_ITEM (Document item in invoice document): 000004
SERIAL_NO (Serial number of account assignment): 03
TAX_CODE (Tax code): V1
ITEM_AMOUNT (Amount in document currency): 350.00
QUANTITY (Quantity): 3
PO_UNIT (Order unit): LE
GL_ACCOUNT (Number of G/L account): 400000
COSTCENTER (Cost center): 3000
The entry in table 'ITEMDATA' adheres to the logic of the display of the items of an incoming invoice in Transaction 'Enter Incoming Invoice' (MIRO).
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.