‎2012 Sep 26 12:53 PM
Hello All,
I want to upload Invoice related data. For that I am using BAPI_ACC_DOCUMENT_POST and passing the data to it from excel for now.
I am getting some errors as below.
1. G/L account 34000 is not defined in chart of accounts INT
I could solve this by keeping account type as Blank for 34000 G/L account in OAMK tcode.
2. Account 11000 in company code 1000 is not a reconciliation account
this error is coming for line item # 2 which is vendor invoice data.
3. FI/CO interface: Inconsistent FI/CO document header data for updating
If I keep account type as 'Vendors' in OAMK tcode for G/L account 11000, My 2nd error is getting solved and I am getting this error.
I am not able to find out the solution for this even after searching in forums.
I am completely new to FI/CO. Please help me on this.
Thanks.
‎2012 Sep 26 3:49 PM
Hi, here is sample code, which u can try.
LOOP AT p_posting INTO l_posting.
l_cnt = sy-tabix.
CLEAR l_amt1.
CLEAR l_amt.
l_amt = -1 * l_posting-wrbtr.
l_amt1 = l_posting-wrbtr.
CONDENSE l_amt.
CONDENSE l_amt1.
CLEAR l_bldat.
*** FM to Convert Date
CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'
EXPORTING
datum = l_posting-bldat
dtype = 'DATS'
IMPORTING
idate = l_bldat.
CLEAR l_budat.
*** FM to Convert Date
CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'
EXPORTING
datum = l_posting-budat
dtype = 'DATS'
IMPORTING
idate = l_budat.
*** FM to get Fiscal Year
CALL FUNCTION 'FTI_FISCAL_YEAR_MONTH_GET'
EXPORTING
i_bukrs = l_posting-bukrs
IMPORTING
e_gjahr = l_docheader-fisc_year.
l_docheader-fisc_year = l_docheader-fisc_year.
l_docheader-username = sy-uname.
l_docheader-header_txt = l_posting-bktxt.
l_docheader-ref_doc_no = l_posting-xblnr.
l_docheader-comp_code = l_posting-bukrs.
l_docheader-doc_date = l_bldat.
l_docheader-pstng_date = l_budat.
l_docheader-doc_type = l_posting-blart.
*** FM to Add Leading Zero
CLEAR l_newko.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_posting-newko
IMPORTING
output = l_newko.
l_v_glacct-itemno_acc = '1'.
l_v_glacct-gl_account = l_newko.
l_v_glacct-comp_code = l_posting-bukrs.
l_v_glacct-pstng_date = l_budat.
l_v_glacct-doc_type = l_posting-blart.
l_v_glacct-profit_ctr = l_posting-prctr.
l_v_glacct-costcenter = l_posting-kostl.
APPEND l_v_glacct TO l_glacct.
l_v_glacct-itemno_acc = '2'.
l_v_glacct-gl_account = '0000999993'.
l_v_glacct-comp_code = l_posting-bukrs.
l_v_glacct-pstng_date = l_budat.
l_v_glacct-doc_type = l_posting-blart.
APPEND l_v_glacct TO l_glacct.
*Make sure total amount balance for a document should be zero
l_v_curramt-itemno_acc = '0000000001'.
l_v_curramt-currency = l_posting-waers.
l_v_curramt-amt_doccur = l_amt.
APPEND l_v_curramt TO l_curramt.
CLEAR l_v_curramt.
l_v_curramt-itemno_acc = '0000000002'.
l_v_curramt-currency = l_posting-waers.
l_v_curramt-amt_doccur = l_posting-wrbtr.
APPEND l_v_curramt TO l_curramt.
CLEAR: l_v_curramt,l_v_glacct.
* Posting the Accounting Document
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = l_docheader
IMPORTING
obj_type = l_objtyp
obj_key = l_objkey
obj_sys = l_objsys
TABLES
accountgl = l_glacct
currencyamount = l_curramt
return = l_return.
IF l_objkey = l_sym.
l_cnt1 = l_cnt1 + 1.
PERFORM return USING l_return.
CLEAR l_curramt .
CLEAR l_glacct.
CLEAR l_docheader.
CONTINUE.
ELSE.
* Case If Document posted Succusfully
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = c_tru.
PERFORM return USING l_return.
l_v_docno = l_objkey+0(10).
* Calling Routine to upload the Clearing Data
PERFORM upload_clearing USING l_v_docno
l_posting.
* ** Calling Call transction
PERFORM bdc_transaction USING 'FCH5'.
l_cnt2 = l_cnt2 + 1 .
CLEAR l_curramt .
CLEAR l_glacct.
CLEAR l_docheader.
ENDIF.
* Counter for new entries
l_cnt = l_cnt + 1.
ENDLOOP.
‎2012 Sep 27 10:26 AM
Hi vipin,
thanks for your reply. I have gone through your code, but couldn't find the solution. I am posting my code here. Please help me out.
loop at it_data into wa_data. “Header Data from excel sheet
at new index.
lv_count = 1.
endat.
wa_documentheader-username = sy-uname.
wa_documentheader-bus_act = 'RFBU'.
wa_documentheader-doc_date = wa_data-bldat.
wa_documentheader-pstng_date = wa_data-budat.
wa_documentheader-doc_type = wa_data-blart.
wa_documentheader-fis_period = wa_data-monat.
wa_documentheader-comp_code = wa_data-bukrs.
loop at it_item into wa_item where index = wa_data-index. “Item Data
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = wa_item-bschl
IMPORTING
OUTPUT = wa_item-bschl.
if wa_item-kunnr is not initial.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = wa_item-kunnr
IMPORTING
OUTPUT = wa_item-kunnr.
endif.
if wa_item-lifnr is not initial.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = wa_item-lifnr
IMPORTING
OUTPUT = wa_item-lifnr.
endif.
case wa_item-bschl.
* when '40'.
when '31'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = wa_item-saknr
IMPORTING
OUTPUT = wa_item-saknr.
wa_accountgl-GL_ACCOUNT = wa_item-saknr.
wa_accountgl-ITEMNO_ACC = lv_count.
wa_accountgl-comp_code = wa_data-bukrs.
wa_accountgl-pstng_date = wa_data-budat.
wa_accountgl-doc_type = wa_data-blart.
wa_accountgl-TAX_CODE = wa_item-MWSKZ.
wa_accountgl-FIS_PERIOD = wa_data-monat.
append wa_accountgl to it_accountgl.
clear wa_accountgl.
wa_currencyamount-itemno_acc = lv_count.
wa_currencyamount-currency_iso = wa_data-waers.
wa_currencyamount-currency = wa_data-waers.
wa_currencyamount-amt_doccur = wa_item-WRBTR.
append wa_currencyamount to it_currencyamount.
clear wa_currencyamount.
when '01'.
select single akont from knb1 into lv_acct where kunnr = wa_item-kunnr and bukrs = wa_data-bukrs.
wa_customeritem-GL_ACCOUNT = lv_acct.
wa_customeritem-ITEMNO_ACC = lv_count.
wa_customeritem-comp_code = wa_data-bukrs.
wa_customeritem-CUSTOMER = wa_item-kunnr.
* wa_customeritem-doc_type = wa_data-blart.
wa_customeritem-TAX_CODE = wa_item-MWSKZ.
append wa_customeritem to it_customeritem.
clear wa_customeritem.
wa_currencyamount-itemno_acc = lv_count.
wa_currencyamount-currency_iso = wa_data-waers.
wa_currencyamount-currency = wa_data-waers.
wa_currencyamount-amt_doccur = wa_item-WRBTR.
append wa_currencyamount to it_currencyamount.
clear wa_currencyamount.
* when '31'.
when '40'.
select single akont from lfb1 into lv_acct where lifnr = wa_item-lifnr and bukrs = wa_data-bukrs.
wa_vendoritem-GL_ACCOUNT = lv_acct.
wa_vendoritem-ITEMNO_ACC = lv_count.
wa_vendoritem-comp_code = wa_data-bukrs.
wa_vendoritem-VENDOR_NO = wa_item-lifnr.
* wa_vendoritem-doc_type = wa_data-blart.
wa_vendoritem-TAX_CODE = wa_item-MWSKZ.
append wa_vendoritem to it_vendoritem.
clear wa_vendoritem.
wa_currencyamount-itemno_acc = lv_count.
wa_currencyamount-currency_iso = wa_data-waers.
wa_currencyamount-currency = wa_data-waers.
wa_currencyamount-amt_doccur = wa_item-WRBTR.
append wa_currencyamount to it_currencyamount.
clear wa_currencyamount.
endcase.
add 1 to lv_count.
endloop.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER = wa_documentheader
* IMPORTING
* OBJ_TYPE = l_awtyp
* OBJ_KEY = l_awkey
* OBJ_SYS = l_awsys
TABLES
ACCOUNTGL = it_accountgl
ACCOUNTRECEIVABLE = it_customeritem
ACCOUNTPAYABLE = it_vendoritem
CURRENCYAMOUNT = it_currencyamount
RETURN = it_return
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
LOOP AT it_return INTO wa_return.
WRITE 😕 wa_return-TYPE,
wa_return-ID,
wa_return-NUMBER,
wa_return-MESSAGE.
clear : wa_return.
ENDLOOP.
clear : wa_documentheader.
refresh : it_accountgl, it_customeritem, it_vendoritem, it_currencyamount, it_return.
endloop.
FYI, I am getting another error for the code which is Period 09 is not allowed. What is this error?
‎2012 Sep 26 3:58 PM
hello,
seems like some of the fields in header that you are passing are not correct. I would suggest you try the data out using FB01 and it works build the variables and data for the FM 'BAPI_ACC_DOCUMENT_POST'. Also do not forget to use FM 'BAPI_TRANSACTION_COMMIT' after the above FM to complete the posting process.
best regards,
swanand
‎2012 Sep 27 10:28 AM
thanks swanand for your reply.
please look at my code and help me with the solution.
‎2012 Sep 28 2:40 PM
Hi
Your coding have this part of interface commented
* IMPORTING
* OBJ_TYPE = l_awtyp
* OBJ_KEY = l_awkey
* OBJ_SYS = l_awsys
Check these notes
SAP Note 306504 - Collective note: BAPIs for the AC interface
SAP Note 333424 - Error messages for tax for Idocs and BAPIs
Period error is related with data in tcode S_ALR_87003642. Use the FM 'FI_PERIOD_CHECK' if you want to check it before calling the BAPI.
I hope this helps you
Regards
Eduardo