01-17-2008 3:13 PM
Hi!
I am using the 'BAPI_INCOMINGINVOICE_CREATE' and it is working perfectly. When the bapi returns message number 534 (Balance not zero: 2,00 debits: XX credits: XX) I need to execute again the bapi with the same information and new value in header-gross_amount (+ 2,00 in this case) on runtime, but ocurrs error, the invoicedocnumber and the table return are initial. The fiscalyear is OK.
When I closed the program and execute again with the same information and new value in header-gross_amount (+2) OK, the bapi working perfectly, invoicedocnumber and fiscalyear are filled.
Ideas?
Thanks!
01-17-2008 3:22 PM
Hi Rodrigo,
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.
IF I_ITAB-TRANS EQ '-'.
I_HEADER-INVOICE_IND = C_X.
ELSE.
CLEAR I_HEADER-INVOICE_IND.
ENDIF.
I_HEADER-PSTNG_DATE = I_ITAB-BUDAT.
I_HEADER-DOC_DATE = I_ITAB-BLDAT.
I_HEADER-CURRENCY = W_WAERS.
I_HEADER-GROSS_AMOUNT = I_ITAB-DMBTR.
I_HEADER-COMP_CODE = I_ITAB-BUKRS.
I_HEADER-HEADER_TXT = I_ITAB-SGTXT.
I_HEADER-REF_DOC_NO = I_ITAB-XBLNR.
IF NOT I_ITAB-INV_REC_DATE IS INITIAL.
I_HEADER-INV_REC_DATE = I_ITAB-INV_REC_DATE.
ELSE.
I_HEADER-INV_REC_DATE = I_ITAB-BLDAT.
ENDIF.
I_HEADER-PYMT_METH = I_ITAB-ZLSCH.
APPEND I_HEADER.
*....
*....
-
Populate Item Table from item data in data file
lv_count = 0.
LOOP AT I_ITAB.
Processing for header records of data file.
lv_count = lv_count + 1.
...........
...........
Item Data
I_ITEM-INVOICE_DOC_ITEM = lv_COUNT.
I_ITEM-PO_NUMBER = I_ITAB-EBELN.
I_ITEM-PO_ITEM = I_ITAB-EBELP.
I_ITEM-TAX_CODE = I_ITAB-MWSKZ2.
I_ITEM-ITEM_AMOUNT = I_ITAB-NETWR.
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'.
I_ACCOUNTINGDATA-TAX_CODE = I_ITAB-MWSKZ2.
I_ACCOUNTINGDATA-ITEM_AMOUNT = I_ITAB-NETWR.
SELECT SINGLE SAKTO KOSTL VBELN VBELP ANLN1 ANLN2 DABRZ
FISTL GEBER GRANT_NBR GSBER IMKEY KOKRS KSTRG PAOBJNR
PRCTR PS_PSP_PNR AUFNR MENGE
FROM EKKN
INTO (I_ACCOUNTINGDATA-GL_ACCOUNT, I_ACCOUNTINGDATA-COSTCENTER,
I_ACCOUNTINGDATA-SD_DOC, I_ACCOUNTINGDATA-SDOC_ITEM,
I_ACCOUNTINGDATA-ASSET_NO, I_ACCOUNTINGDATA-SUB_NUMBER,
I_ACCOUNTINGDATA-REF_DATE, I_ACCOUNTINGDATA-FUNDS_CTR,
I_ACCOUNTINGDATA-FUND, I_ACCOUNTINGDATA-GRANT_NBR,
I_ACCOUNTINGDATA-BUS_AREA, I_ACCOUNTINGDATA-RL_EST_KEY,
I_ACCOUNTINGDATA-CO_AREA, I_ACCOUNTINGDATA-COSTOBJECT,
I_ACCOUNTINGDATA-PROFIT_SEGM_NO, I_ACCOUNTINGDATA-PROFIT_CTR,
I_ACCOUNTINGDATA-WBS_ELEM, I_ACCOUNTINGDATA-ORDERID,
I_ACCOUNTINGDATA-QUANTITY)
WHERE EBELN EQ I_ITAB-EBELN
AND EBELP EQ I_ITAB-EBELP
AND ZEKKN EQ '01'.
IF EKKO-BSART NE 'LTV'.
CLEAR I_ACCOUNTINGDATA-QUANTITY.
CLEAR I_ACCOUNTINGDATA-PO_UNIT.
ENDIF.
APPEND I_ACCOUNTINGDATA.
ENDIF.
*.....
*.....
ENDLOOP.
-
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.
IF W_COUNTER EQ 1.
I_ACCOUNTINGDATA-SERIAL_NO = '01'.
I_ACCOUNTINGDATA-XUNPL = ' '.
ELSE.
I_ACCOUNTINGDATA-SERIAL_NO = ' '.
I_ACCOUNTINGDATA-XUNPL = 'X'.
ENDIF.
MODIFY I_ACCOUNTINGDATA
TRANSPORTING SERIAL_NO XUNPL
WHERE INVOICE_DOC_ITEM = I_ITEM-INVOICE_DOC_ITEM.
W_COUNTER = W_COUNTER + 1.
ENDLOOP.
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.
IF W_COUNTER EQ 1.
I_ACCOUNTINGDATA-SERIAL_NO = '01'.
I_ACCOUNTINGDATA-XUNPL = ' '.
ELSE.
I_ACCOUNTINGDATA-SERIAL_NO = ' '.
I_ACCOUNTINGDATA-XUNPL = 'X'.
ENDIF.
MODIFY I_ACCOUNTINGDATA
TRANSPORTING SERIAL_NO XUNPL
WHERE INVOICE_DOC_ITEM = I_ITEM-INVOICE_DOC_ITEM.
W_COUNTER = W_COUNTER + 1.
ENDLOOP.
ENDON.
ENDLOOP.
Changes over for OSS Note 518338.
SORT I_ITEM BY INVOICE_DOC_ITEM PO_NUMBER PO_ITEM.
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
HEADERDATA = I_HEADER
IMPORTING
INVOICEDOCNUMBER = W_BELNR
FISCALYEAR = W_GJAHR
TABLES
ITEMDATA = I_ITEM
ACCOUNTINGDATA = I_ACCOUNTINGDATA
TAXDATA = I_TAX
RETURN = I_RETURN.
if sy-subrc 0.
message e999(re) with 'Problem occured'.
else.
loop at return.
if not return is initial.
clear bapi_retn_info.
move-corresponding return to bapi_retn_info.
if return-type = 'A' or return-type = 'E'.
error_flag = 'X'.
endif.
append bapi_retn_info.
endif.
endloop.
if error_flag = 'X'.
message e999(re) with 'Problem occured'.
rollback work.
else.
Return Table from BAPI call is empty
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = I_RETURN.
endif.
endif.
kindly reward if found helpful.
cheers,
Hema.
01-17-2008 8:09 PM
<B>THE ERROR</B>
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
headerdata = st_header
IMPORTING
invoicedocnumber = v_number
fiscalyear = v_year
TABLES
itemdata = t_item
return = t_return.
IF v_number IS INITIAL OR
v_year IS INITIAL.
READ TABLE t_return INTO st_return WITH KEY id = 'M8' number = '534'.
IF SY-SUBRC IS INITIAL.
<b>
Here the program execute the 'BAPI_INCOMINGINVOICE_CREATE' again with the same information and st_header-gross_amount with new value, but v_number is initial again. But I close the program and execute again with new value in st_header-gross_amount v_number returns OK.
</b>
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.