2010 Dec 14 6:51 AM
Hi ALL THE ABAP GURUS,
I am creating a program for document posting with multiple Special G/L with BAPI BAPI_ACC_DOCUMENT_POST. It is working fine .When I transported it to Quality server, for B G/L with account say 322340 it was asking to enter Tax Code.So in development I am trying to fill ACCOUNTTAX Table of this BAPI. For the Account 322340 we need Nil as Tax code and I wrote Tax_Code as 'V0'. Now it is asking for ACCT_KEY and COND_KEY. From where to find it. Some part of code is
WA_ACCOUNTTAX-GL_ACCOUNT = W_ITAB-HKONT. " Here 322340 ie for B indicator
WA_ACCOUNTTAX-TAX_CODE = 'V0'.
WA_ACCOUNTTAX-ACCT_KEY = ???
WA_ACCOUNTTAX-COND_KEY = ???.
For BUKRS = GIL it is giving the error Error in account determination: table GIL key VS6 V0
Thanks In Advance,
Bharti Jain
2010 Dec 14 7:27 AM
Hello,
Here Codition key is Condition type and acct ket is transaction key.
Thanks,
Sumit Joshi
2010 Dec 14 7:25 AM
Hello Bharti,
You can find required information by this:
Fetch Chart of account for given country
select single
ktopl "Chart of Accounts
waers "Currency
into wa_t001
from t001
where bukrs eq p_bukrs.
if sy-subrc eq 0.
Fetch GL a/c for tax code and Transaction Key
select ktosl "Transaction Key
mwskz "Sales Tax Code
konts "GL A/C
into table i_taxgl
from t030k
for all entries in i_tax
where ktopl eq wa_t001-ktopl
and mwskz eq i_tax-tax_code.
if sy-subrc eq 0.
Fetch country Key for Company Code
select single land1 "country Key
into v_land1
from t001
where bukrs eq p_bukrs.
if sy-subrc eq 0.
Get Condition type for country Key and Sales Tax Code
select kschl "Condition type
mwskz "Sales Tax Code
knumh "Condition record number
into table i_a003
from a003
for all entries in i_tax
where aland eq v_land1
and mwskz eq i_tax-tax_code.
if sy-subrc eq 0.
Get Tax rate
select knumh "Condition record number
kbetr "Rate (condition amount or percentage)
into table i_konp
from konp
for all entries in i_a003
where knumh eq i_a003-knumh.
if sy-subrc <> 0.
refresh: i_konp.
endif.
endif.
endif.
endif.
endif.
2010 Dec 14 7:27 AM
Hello,
Here Codition key is Condition type and acct ket is transaction key.
Thanks,
Sumit Joshi
2010 Dec 14 8:46 AM
Thanks for the reply.
I have tried as suggested by you but I am getting error as Error in account determination: table GIL key VS6 V0.
Regards,
Bharti Jain
2010 Dec 14 9:10 AM
Simulate the scenario by creating the FI document using FB01. Check the value in table field BSET-KSCHL which should be passed to WA_ACCOUNTTAX-COND_KEY while calling bapi. As per the BAPI documentation structure field WA_ACCOUNTTAX-ACCT_KEY is not mandatory.
2010 Dec 14 10:38 AM
Hi ALL The GURUS,
As suggested by Vinod Sir I have done the steps and now it is giving another error
Please find the code snippet. Here T_ITAB contains the Vendor entry and T_FINALN contains the BANK entry. This is done so because there may be multiple documents for a vendor with different Special G/L indicator and for the Bank only one entry is to done.
COUNT = 0.
LOOP AT T_ITAB INTO W_ITAB WHERE CHECK = 'X'. " Check = 'X' indicates multiple document selected from ALV
DOCHEADER-USERNAME = SY-UNAME.
DOCHEADER-COMP_CODE = W_ITAB-BUKRS.
DOCHEADER-BUS_ACT = W_ITAB-GLVOR.
DOCHEADER-FISC_YEAR = W_ITAB-GJAHR.
DOCHEADER-REF_DOC_NO = W_ITAB-XBLNR.
DOCHEADER-DOC_DATE = W_ITAB-BLDAT.
DOCHEADER-PSTNG_DATE = W_ITAB-BUDAT.
DOCHEADER-TRANS_DATE = W_ITAB-WWERT.
DOCHEADER-FIS_PERIOD = W_ITAB-MONAT.
DOCHEADER-DOC_TYPE = 'KZ'.
ADD 1 TO COUNT.
WA_ACCOUNTPAY-ITEMNO_ACC = COUNT.
WA_ACCOUNTPAY-VENDOR_NO = W_ITAB-LIFNR.
WA_ACCOUNTPAY-GL_ACCOUNT = W_ITAB-HKONT.
WA_ACCOUNTPAY-GL_ACCOUNT = '0000428010'.
WA_ACCOUNTPAY-PMNTTRMS = W_ITAB-ZTERM.
WA_ACCOUNTPAY-BLINE_DATE = W_ITAB-ZFBDT.
WA_ACCOUNTPAY-BUSINESSPLACE = W_ITAB-BUPLA.
WA_ACCOUNTPAY-SECTIONCODE = W_ITAB-SECCO.
WA_ACCOUNTPAY-ALLOC_NMBR = W_ITAB-ZUONR.
WA_ACCOUNTPAY-ITEM_TEXT = W_ITAB-SGTXT.
WA_ACCOUNTPAY-W_TAX_CODE = W_ITAB-QSSKZ.
WA_ACCOUNTPAY-COMP_CODE = W_ITAB-BUKRS.
WA_ACCOUNTPAY-PROFIT_CTR = W_ITAB-PRCTR.
WA_ACCOUNTPAY-SP_GL_IND = W_ITAB-ZUMSK.
APPEND WA_ACCOUNTPAY TO ACCOUNTPAY.
CLEAR: WA_ACCOUNTPAY.
MOVE W_ITAB-EBELN TO WA_EXTENSION1-FIELD1.
MOVE W_ITAB-EBELP TO WA_EXTENSION1-FIELD2.
MOVE W_ITAB-POSKI TO WA_EXTENSION1-FIELD3.
MOVE W_ITAB-PROJK TO WA_EXTENSION1-FIELD3.
MOVE W_ITAB-HKONT TO WA_EXTENSION1-FIELD4.
APPEND WA_EXTENSION1 TO EXTENSION1.
CLEAR: WA_EXTENSION1.
WA_CURRAMOUNT-ITEMNO_ACC = COUNT. " " Line Item Number
WA_CURRAMOUNT-CURR_TYPE = '00'. " " Currency Type
WA_CURRAMOUNT-CURRENCY = W_ITAB-WAERS. " " Currency Key
WA_CURRAMOUNT-CURRENCY_ISO = W_ITAB-WAERS. " " ISO Code
WA_CURRAMOUNT-AMT_DOCCUR = W_ITAB-WRBTR. " " Amount
WA_CURRAMOUNT-AMT_BASE = W_ITAB-DMBTR.
APPEND WA_CURRAMOUNT TO CURRAMOUNT.
CLEAR: WA_CURRAMOUNT.
ADD 1 TO COUNT.
WA_ACCOUNTTAX-ITEMNO_ACC = COUNT.
WA_ACCOUNTTAX-GL_ACCOUNT = '0000428370'.
WA_ACCOUNTTAX-TAX_CODE = 'V0'.
WA_ACCOUNTTAX-ACCT_KEY = 'VS1'.
WA_ACCOUNTTAX-COND_KEY = 'JMOP'.
APPEND WA_ACCOUNTTAX TO ACCOUNTTAX.
CLEAR: WA_ACCOUNTTAX.
ENDLOOP.
COUNT = 1.
LOOP AT T_FINALN INTO W_FINALN.
ADD 1 TO COUNT.
WA_ACCOUNTGL-ITEMNO_ACC = COUNT. " " Line Item Number
WA_ACCOUNTGL-GL_ACCOUNT = HKONT. " " GL Account Number
WA_ACCOUNTGL-COMP_CODE = W_FINALN-BUKRS. " " Company Code
WA_ACCOUNTGL-PSTNG_DATE = W_FINALN-BUDAT. " " Posting Date
WA_ACCOUNTGL-DOC_TYPE = 'KZ'. "SA " " Document Type
WA_ACCOUNTGL-FISC_YEAR = W_FINALN-GJAHR. " " Fiscal Year
WA_ACCOUNTGL-FIS_PERIOD = W_FINALN-MONAT. " " Fiscal Period
WA_ACCOUNTGL-ITEM_TEXT = ''. " " Item Text
WA_ACCOUNTGL-ALLOC_NMBR = ''.
wa_accountgl-bus_area = '2500'.
wa_accountgl-acct_type = 'K'.
WA_ACCOUNTGL-PROFIT_CTR = V_PRCTR.
APPEND WA_ACCOUNTGL TO ACCOUNTGL.
CLEAR WA_ACCOUNTGL.
WA_CURRAMOUNT-ITEMNO_ACC = COUNT. " " Line Item Number
WA_CURRAMOUNT-CURR_TYPE = '00'. " " Currency Type
WA_CURRAMOUNT-CURRENCY = W_FINALN-WAERS. " " Currency Key
WA_CURRAMOUNT-CURRENCY_ISO = W_FINALN-WAERS. " " ISO Code
WA_CURRAMOUNT-AMT_DOCCUR = V_WRBTR * -1. " " Amount
WA_CURRAMOUNT-AMT_BASE = W_FINALN-DMBTR. " " Base Amount
APPEND WA_CURRAMOUNT TO CURRAMOUNT.
CLEAR WA_CURRAMOUNT.
WA_ACCOUNTWT-ITEMNO_ACC = COUNT.
WA_ACCOUNTWT-WT_TYPE = W_FINALN-MWART.
WA_ACCOUNTWT-WT_CODE = W_FINALN-QSSKZ.
WA_ACCOUNTWT-BAS_AMT_LC = W_FINALN-QSSHB.
WA_ACCOUNTWT-BAS_AMT_TC = W_FINALN-FWBAS.
WA_ACCOUNTWT-BAS_AMT_IND = 'X'.
APPEND WA_ACCOUNTWT TO ACCOUNTWT.
CLEAR: WA_ACCOUNTWT.
ENDLOOP.
After the BAPI_ACC_DOCUMENT_POST is called then it is giving error in RETURN Table
FI/CO interface: Line item entered several times and MESSAGE_V3 = 0000000002
Thanks In Advance,
Regards,
Edited by: Bharti Jain on Dec 14, 2010 11:38 AM
2010 Dec 14 10:53 AM
Something wrong with the way you are passing value to document Line item (ITEMNO_ACC). Irrespective of the structure used (Vendor,Customer,GL), ITEMNO_ACC should be distinct. Hope you got an idea about the error.
2010 Dec 14 11:23 AM
Thanks Vinod Sir,
As suggested I have corrected the same but now it is giving another error Tax Code must be entered.
But I have mentioned Tax Code as V0.
Regards,
Bharti Jain
2010 Dec 14 11:44 AM
Hi ALL The ABAP Gurus,
I want that the Tax Code should be nill so I entered 'V0' but it is saying Tax Code must be entered.
When I post the Document through F-02 with V0 as Tax Code For B Spl. G/L indicator it has successfully posted.
Where I have committed mistake?
Thanks & Regards,
Bharti Jain
2010 Dec 15 3:10 AM
Hi All The ABAP GURUS,
I have written the following code for ACCOUNTTAX Table
WA_ACCOUNTTAX-ITEMNO_ACC = COUNT.
WA_ACCOUNTTAX-GL_ACCOUNT = '0000428370'.
WA_ACCOUNTTAX-TAX_CODE = 'V0'.
WA_ACCOUNTTAX-ACCT_KEY = 'VS1'.
WA_ACCOUNTTAX-COND_KEY = 'JMOP'.
APPEND WA_ACCOUNTTAX TO ACCOUNTTAX.
CLEAR: WA_ACCOUNTTAX.
I have to mention Nill as Tax so I have added V0 .Even then it is giving error Tax Code must be entered. Please suggest me in this matter where I have done wrong.
Thanks & Regards,
Bharti Jain
2010 Dec 15 7:36 AM
Hello,
I believe you are mistaking while filling all required fields into BAPI's structures and tables.
You can refer this:
1. Filling Header data:
wa_dochead-username = v_syuname. "User Name
wa_dochead-comp_code = p_bukrs. "Company Code
wa_dochead-doc_date = p_bldat. "Invoice date
wa_dochead-pstng_date = p_budat. "Posting date
wa_dochead-doc_type = p_blart. "Document Type
wa_dochead-ref_doc_no = p_xblnr. "Reference
2. Filling GL A/C Item data:
v_item_no = 1. "Item no reserve for vendor
loop at i_items into wa_items.
A/C GL
add 1 to v_item_no.
wa_glac-itemno_acc = v_item_no. "Item No
wa_glac-gl_account = wa_items-cost_element. "GL A/C Number
wa_glac-item_text = wa_items-text. "Item Text
wa_glac-doc_type = p_blart. "Document Type
wa_glac-comp_code = p_bukrs. "Company Code
wa_glac-pstng_date = p_budat. "Posting Date in the Document
wa_glac-trade_id = wa_items-trade_part. "Company ID of Trading Partner
wa_glac-tax_code = wa_items-tax_code. "Tax Code
wa_glac-costcenter = wa_items-cost_center. "Cost Center
wa_glac-alloc_nmbr = wa_items-assignment. "Assignment Number
wa_glac-acct_type = c_s. "A/C type
perform f_conversion_exit_alpha_input "Add Leading Zeros
changing wa_glac-trade_id.
perform f_conversion_exit_alpha_input
changing wa_glac-gl_account.
perform f_conversion_exit_alpha_input
changing wa_glac-costcenter.
append wa_glac to i_glac.
Currency amount (posting key-40)
wa_curr-itemno_acc = v_item_no. "Item No
wa_curr-currency_iso = p_waers. "Currency ISO
wa_curr-currency = p_waers. "Currency
wa_curr-amt_doccur = wa_items-amount. "Amount on Item
append wa_curr to i_curr. clear wa_curr.
v_totamt = v_totamt + wa_items-amount. "Add item amount to total amount
read table i_tax into wa_tax with key tax_code = wa_items-tax_code. "If tax code is same with previous item
if sy-subrc eq 0.
wa_tax-tax_amt = wa_tax-tax_amt + wa_items-amount. "Add amount corresponding to tax code
modify i_tax from wa_tax index sy-tabix.
else. "If tax code is not same with previous item
clear: wa_tax.
wa_tax-tax_code = wa_items-tax_code. "Assign tax code to wa_tax for show taxes
wa_tax-tax_amt = wa_items-amount. "Assign item amount to wa_tax for show taxes
append wa_tax to i_tax.
endif.
clear: wa_curr, wa_acpayable, wa_glac, wa_items, wa_actax, wa_tax.
endloop.
3. Filling Tax data:
loop at i_tax into wa_tax.
add 1 to v_item_no. "Item No
Get Condition type for country Key and Sales Tax Code
read table i_a003 into wa_a003 with key mwskz = wa_tax-tax_code.
if sy-subrc eq 0.
Get Tax rate
read table i_konp into wa_konp with key knumh = wa_a003-knumh.
if sy-subrc eq 0.
wa_konp-kbetr = wa_konp-kbetr / 10. "Get Tax percentage
wa_actax-tax_rate = wa_konp-kbetr. "Tax rate
v_amt = ( wa_konp-kbetr / c_100 ) * wa_tax-tax_amt. "Tax amount
v_totamt = v_totamt + v_amt.
Get GL a/c for tax code and Transaction Key
read table i_taxgl into wa_taxgl with key mwskz = wa_tax-tax_code.
if sy-subrc eq 0.
Fill Tax account
wa_actax-itemno_acc = v_item_no. "Item No
wa_actax-gl_account = wa_taxgl-konts. "GL Account for Tax
wa_actax-cond_key = wa_a003-kschl. "Condition Type
wa_actax-acct_key = wa_taxgl-ktosl. "Transaction Key
wa_actax-tax_code = wa_tax-tax_code. "Sales Tax Code
perform f_conversion_exit_alpha_input "Add Leading Zeros
changing wa_actax-gl_account.
append wa_actax to i_actax.
Fill Currency for Tax
Currency amount (posting key-40)
wa_curr-itemno_acc = v_item_no. "Item No
wa_curr-currency_iso = p_waers. "Currency ISO
wa_curr-currency = p_waers. "Currency
wa_curr-amt_doccur = v_amt. "Tax amount
wa_curr-amt_base = wa_tax-tax_amt. "Base amount
append wa_curr to i_curr.
endif.
endif.
endif.
clear: wa_tax, wa_actax, wa_curr, wa_a003, wa_taxgl, v_land1, v_amt.
endloop.
4. Filling Vendor data:
A/C payable
wa_acpayable-itemno_acc = c_1. "Item No
wa_acpayable-vendor_no = p_lifnr. "Account Number of Vendor or Creditor
wa_acpayable-comp_code = p_bukrs. "Company Code
wa_acpayable-tax_code = p_mwskz. "Sales Tax Code
perform f_conversion_exit_alpha_input "Add Leading Zeros
changing wa_acpayable-vendor_no.
append wa_acpayable to i_acpayable.
*Currency amount (posting key-31)
wa_curr-itemno_acc = c_1. "Item No
wa_curr-currency_iso = p_waers. "Currency ISO
wa_curr-currency = p_waers. "Currency
wa_curr-amt_doccur = v_totamt * -1. "Total Amount
append wa_curr to i_curr.
5. Doc posting:
Check the document
call function 'BAPI_ACC_DOCUMENT_CHECK'
exporting
documentheader = wa_dochead "Document Header
tables
accountgl = i_glac "GL A/C Item
accountpayable = i_acpayable "Vendor
accounttax = i_actax "Tax
currencyamount = i_curr "Currency
return = i_return. "Return messages
read table i_return into wa_return with key number = c_614. "Success
if sy-subrc eq 0. "If document is ok
refresh: i_return.
call function 'BAPI_ACC_DOCUMENT_POST' "Document posting
exporting
documentheader = wa_dochead "Document Header
importing
obj_key = v_obj_key "Reference key
obj_sys = v_obj_sys "Logical system
tables
accountgl = i_glac "GL A/C Item
accountpayable = i_acpayable "Vendor
accounttax = i_actax "Tax
currencyamount = i_curr "Currency
return = i_return. "Return messages
read table i_return into wa_return with key number = c_605. "Success
if sy-subrc eq 0. "If successfully posted
call function 'BAPI_TRANSACTION_COMMIT'. "Commit Bapi
endif.
endif.
Thanks,
Sumit Joshi
2010 Dec 15 8:51 AM
Thanks Sumit Sir,
I have corrected as you have suggested and now it is working.
Continuing in this issue there is another issue that after posting document through BAPI_ACC_DOCUMENT_POST there are some updations related PO History. When I posted document through F-02 and look in the PO History Tab of ME23N then above Tr./Ev. Down payment I can see the document in Material Document column along with other details updated.
But when I post the document through my program these are not updated.
Is there any FM which I have to call to update that.
Thanks in Advance,
Regards,
Bharti Jain
2010 Dec 15 10:50 AM
Hi All The GURUS,
How to update the PO History details after F-02 deocument posting ? Is there any function module to do that.
Regards,
Bharti Jain