‎2012 Jul 04 6:19 PM
Hi all, I'm using this BAPI, and it works fine,
but now the requirement is to add the tax calculation.
I add the i_accountax to the call:
* Posting to accounting.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = w_header
IMPORTING
obj_type = l_type
obj_key = l_key
obj_sys = l_sys
TABLES
accountgl = i_accountgl
accountreceivable = i_accountre
accounttax = i_accountax
currencyamount = i_curren
return = i_return.
I execute the BAPI with following data:
| w_header | |
| BUS_ACT | RFBU |
| USERNAME | CGOMEZ |
| HEADER_TXT | VTA. PROD. Y/O SERVI |
| COMP_CODE | 3000 |
| DOC_DATE | 20120625 |
| PSTNG_DATE | 20120625 |
| FISC_YEAR | 2012 |
| FIS_PERIOD | 6 |
| DOC_TYPE | DR |
| REF_DOC_NO | 117 |
| i_curren | ||||||||||
| ITEMNO_ACC | CURRENCY | AMT_DOCCUR | AMT_BASE | TAX_AMT | ||||||
| 30 | MXN | 48418.4000- | 41740.0000- | 6678.4000- | ||||||
| 20 | MXN | 34962.4000- | 30140.0000- | 4822.4000- | ||||||
| 10 | MXN | 83380.8 | 71880 | 11500.8 | ||||||
| i_accountre | ||||||||||
| ITEMNO_ACC | CUSTOMER | GL_ACCOUNT | COMP_CODE | PMNTTRMS | BLINE_DATE | ITEM_TEXT | TAX_CODE | |||
| 10 | 300005 | 121000 | 3000 | NT30 | 20120625 | Venta Aceite Usado | A2 | |||
| i_accountgl | ||||||||||
| ITEMNO_ACC | GL_ACCOUNT | ITEM_TEXT | COMP_CODE | PLANT | FIS_PERIOD | FISC_YEAR | PSTNG_DATE | VALUE_DATE | TAX_CODE | COSTCENTER |
| 20 | 700100 | Aceite Usado, Nov 20 | 3000 | 3000 | 6 | 2012 | 20120625 | 20120625 | A2 | 3061000002 |
| 30 | 700100 | Aceite Usado, Dic 20 | 3000 | 3000 | 6 | 2012 | 20120625 | 20120625 | A2 | 3061000002 |
And i_accountax:
ITEMNO_ACC | GL_ACCOUNT | TAX_CODE | DIRECT_TAX |
30 | 230005 | A2 | X |
20 | 230005 | A2 | X |
10 | 230005 | A2 | X |
When I test the code, I get the error:
E RW 14 FI/CO interface: Line item entered several times $ 0000000010 0 QASCLNT010
What am I doing wrong?
I will appreciate any guidance with this.
‎2012 Jul 04 6:46 PM
Hi
I suppose the problem is you're appending some items twice: one in customer or g/l section and one in tax section.
You need to insert those items in one section only, so in tax section you should set only one item (I suppose 40) for tax
Max
‎2012 Jul 04 6:58 PM
Thanks for your reply Max,
I changed the information i_accountax as you suggested, I also added the COND_KEY:
| ITEMNO_ACC | GL_ACCOUNT | COND_KEY | TAX_CODE | DIRECT_TAX |
| 40 | 230005 | MWAS | A2 | X |
But now returns the error:
| No currency line exists for line item 0000000040 | 000000 | 0000000040 | ACCOUNTTAX |
‎2012 Jul 04 7:10 PM
Check this link
http://www.sapfans.com/forums/viewtopic.php?t=137643&highlight=bapiaccdocumentpost
it's very similar to your requirement.
‎2012 Jul 04 8:07 PM
Hi
You need to add the line in currency section of course:
You can use the fm CALCULATE_TAX_FROM_NET_AMOUNT in order to calculate the amount to be assigned
Max
‎2012 Jul 06 7:46 PM
Thanks for reply Max, I think I don't have to calculate the tax myself,
we are going to get that info from a file. In i_curren I have to add the
line and 11500.8 is the tax amount, but I don't know how to fill correctly
the i_curren structure, I'm getting the error:
Balance in transaction currency
| i_curren | ||||
| ITEMNO_ACC | CURRENCY | AMT_DOCCUR | AMT_BASE | TAX_AMT |
| 30 | MXN | 48418.4000- | 41740.0000- | 6678.4000- |
| 20 | MXN | 34962.4000- | 30140.0000- | 4822.4000- |
| 10 | MXN | 83380.8 | 71880 | 11500.8 |
How should I fill the row missing?
‎2012 Jul 06 8:40 PM
Hi
I believe you need to tranfer the net amount to G/L item:
| ITEMNO_ACC | CURRENCY | AMOUNT |
|---|---|---|
| 10 | MXN | 83380.80 |
| 20 | MXN | -30140.00 |
| 30 | MXN | -41740.00 |
| 40 | MXN | -11500.80 |
I don't believe you need to fill the tax and base amount
Max
‎2012 Jul 09 11:01 PM
Thanks a lot Max!
That solved the problem
Now I need to add the witholding tax calculation, I have the data in the file too, but I don't know how to fill the accountwt table. I'm filling the tables this way:
i_accountwt
ITEMNO_ACC | WT_TYPE | WT_CODE | BAS_AMT_LC | AWH_AMT_LC |
12 | M6 | 2 | 71880.0000- | 11500.8000- |
i_accountax
ITEMNO_ACC | GL_ACCOUNT | COND_KEY | ACCT_KEY | TAX_CODE | DIRECT_TAX |
11 | 230005 | MWAS | MWS | A2 | X |
i_curren
ITEMNO_ACC | CURRENCY | AMT_DOCUR | AMT_BASE | TAX_AMT |
30 | MXN | 41740.0000- | 6678.4000- | |
20 | MX | 30140.0000 | 4822.4000- | |
11 | MXN | 11500.8000 | 71880.0000 | |
12 | MXN | 11500.8000 | 71880.0000 | |
10 | MXN | 83380.8000 | 71880.0000 | 11500.8000 |
What am I doing wrong?
‎2012 Jul 10 2:07 PM
Hi
I suppose the ITEMNO_ACC is item number of item vendor, so here you need to indicate the base amount only (usually the withholding tax value will be calculated automatically while clearing the document):
| ITEMNO_ACC | WT_TYPE | WT_CODE | BAS_AMT_TC |
|---|---|---|---|
| <vendor item number> | M6 | 2 | base amount |
The base amount depends on the type of withholding tax code: usually it's just a part only of the net amount of vendor
Max
‎2012 Jul 10 4:52 PM
Thanks again Max,
I changed the i_accountwt as you suggested.
But It doesn't appear the witholding tax line in the document at the end. I filled i_curren this way:
And this is the document generated:
Any idea how to solve the issue?
‎2012 Jul 10 5:05 PM
Hi
The witholding tax shouldn't be shown in the items of the document, but in a special section of your document.
You should see the a push button in the menu bar to go to withholding tax data.
Max
‎2012 Jul 10 5:47 PM
The thing is that is showing that line in a document generated manually.
Perhaps is a configuration issue?
‎2012 Oct 16 12:19 PM
Hi,
I think you do not need to append negative amount, just provide posting keys and based on posting keys SAP will calculate the balance.
Regards,
Prashant
‎2014 Aug 05 8:15 AM
Hi Karina,
How would you solve this, i am facing same. Could you please help me out.
Thanks in advance.
Ramesh J.
‎2012 Oct 16 12:00 PM
Hello karina.
Could you please help me out. I am also stuck with the same problem. How to fill the accounttax and corresponding currencyamount enteries for service tax calculation ? I am using
CALCULATE_TAX_FROM_NET_AMOUNT to calculate the tax amount. How should I pass it into various tables of bapi. What should be the AMT-base, amt-doccur for posting key 40 ?
‎2013 Jul 30 12:27 PM
‎2013 Jul 31 9:48 AM
Hi,
Please find the code:
CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
EXPORTING
I_BUKRS = wa_hdr2-bukrs
I_MWSKZ = wa_hdr2-mwskz
* I_TXJCD = ' '
I_WAERS = 'INR'
I_WRBTR = wrbtr
IMPORTING
* E_FWNAV =
* E_FWNVV =
E_FWSTE = fwste
tables
T_MWDAT = T_MWDAT
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
wa_hdr2-ZRB_STAMT1 = wrbtr + fwste.
*dtlamt = wa_hdr2-ZRB_STAMT.
*condense dtlamt.
ENDIF.
***G/L bill wise Line item entries
it_accgl-ITEMNO_ACC = count.
it_accgl-GL_ACCOUNT = wa_hdr2-saknr1.
it_accgl-item_text = wa_hdr2-zrb_schno.
it_accgl-comp_code = wa_hdr2-bukrs.
*read table it_aufk with key aufnr = wa_hdr2-aufnr.
*IF sy-subrc = 0.
*it_accgl-bus_area = it_aufk-gsber.
*it_accgl-item_text = it_aufk-ktext.
*ENDIF.
*it_accgl-plant = wa_hdr-werks.
it_accgl-FISC_YEAR = l_gjahr."wa_hdr2-gjahr.
*it_accgl-VENDOR_NO = wa_hdr2-lifnr.
it_accgl-TAX_CODE = wa_hdr2-mwskz.
*it_accgl-ALLOC_NMBR = wa_hdr2-zrb_refno. " Doubt
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = wa_hdr2-kostl
IMPORTING
OUTPUT = it_accgl-COSTCENTER.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = wa_hdr2-prctr
IMPORTING
OUTPUT = it_accgl-PROFIT_CTR.
*it_accgl-COSTCENTER = wa_hdr2-kostl.
*it_accgl-PROFIT_CTR = wa_hdr2-prctr.
*it_accgl-orderid = wa_hdr2-aufnr. " Order Number
*it_accgl-BILL_TYPE = it_wb2-fkart.
**it_accgl-sales_ord = it_wb2-auble.
**it_accgl-S_ORD_ITEM = wa_hdr2-posnr.
*it_accgl-DISTR_CHAN = it_wb2-vtweg.
*it_accgl-DIVISION = wa_hdr2-spart.
*it_accgl-SALESORG = wa_hdr2-vkorg.
*it_accgl-sales_grp = it_wb2-vkgrp.
*it_accgl-sales_off = it_wb2-vkbur.
*it_accgl-sold_to = wa_hdr2-kunnr.
**it_accgl-DE_CRE_IND = 'S'.
*it_accgl-BASE_UOM = 'TO'.
*it_accgl-INV_QTY_SU = wa_hdr2-fkimg.
*it_accgl-MATERIAL = it_wb2-matnr.
append it_accgl.
clear it_accgl.
*IF wa_hdr2-shkzg = 'S'.
*cramt = 0 - cramt.
**wa_hdr-zrb_secamt = 0 - wa_hdr-zrb_secamt.
*ENDIF.
**************Vendor
it_vend-ITEMNO_ACC = 1.
it_vend-VENDOR_NO = wa_hdr2-lifnr.
it_vend-tax_code = wa_hdr2-mwskz.
it_vend-comp_code = wa_hdr2-bukrs.
* read table it_aufk with key aufnr = wa_hdr2-aufnr.
* IF sy-subrc = 0.
* it_vend-bus_area = it_aufk-gsber.
* it_vend-item_text = it_aufk-ktext.
* ENDIF.
it_vend-ALLOC_NMBR = wa_hdr2-aufnr.
IT_VEND-BUSINESSPLACE = wa_hdr2-bupla."werks.
IT_VEND-SECTIONCODE = wa_hdr2-bupla."werks.
* it_vend-ref_key_1 = wa_hdr-aufnr.
* it_vend-bline_date = us_dt.
SELECT SINGLE ZTERM from lfb1 INTO it_vend-PMNTTRMS WHERE lifnr = wa_hdr2-lifnr.
* it_vend-PMNTTRMS =
if wrbtr is not initial.
append it_vend.
endif.
*IF wa_hdr2-shkzg = 'H'.
wa_hdr2-ZRB_STAMT1 = 0 - wa_hdr2-ZRB_STAMT1. "Vendor Amt
*ENDIF.
**************Vendor
it_curr-ITEMNO_ACC = 1.
it_curr-CURRENCY = 'INR'.
it_curr-AMT_DOCCUR = wa_hdr2-ZRB_STAMT1.
append it_curr.
clear it_curr.
clear it_cust.
if wrbtr is not initial.
*cramt = 0 - cramt.
it_curr-ITEMNO_ACC = count.
it_curr-CURRENCY = 'INR'.
it_curr-AMT_DOCCUR = wrbtr.
append it_curr.
endif.
clear it_curr.
****** Filling Tax Table
count = count + 1.
LOOP AT t_mwdat.
it_curr-ITEMNO_ACC = count.
it_curr-AMT_DOCCUR = t_mwdat-wmwst.
it_curr-CURRENCY = 'INR'.
it_curr-amt_base = t_mwdat-kawrt.
it_tax-ITEMNO_ACC = count.
it_tax-GL_ACCOUNT = t_mwdat-hkont.
it_tax-COND_KEY = t_mwdat-KSCHL.
it_tax-ACCT_KEY = t_mwdat-KTOSL.
it_tax-TAX_CODE = wa_hdr2-mwskz.
it_tax-DIRECT_TAX = 'X'.
append it_curr.
append it_tax.
clear: it_tax,it_curr.
count = count + 1.
ENDLOOP.
*****filling Withholding Tax
loop at it_taxcode.
READ TABLE IT_LFBW WITH KEY WITHT = it_taxcode-WITHT.
IF SY-SUBRC = 0.
it_wtax-ITEMNO_ACC = 1.
it_wtax-WT_TYPE = it_taxcode-WITHT.
it_wtax-WT_CODE = it_taxcode-WT_WITHCD.
append it_wtax.
clear it_wtax.
ENDIF.
ENDLOOP.
*****Filling Document Header
if cramt is not initial.
wa_dochdr-USERNAME = sy-uname.
wa_dochdr-HEADER_TXT = wa_hdr2-zrb_schno."
wa_dochdr-comp_code = wa_hdr2-bukrs.
wa_dochdr-DOC_DATE = wa_hdr2-bldat."us_dt.
wa_dochdr-PSTNG_DATE = us_dt.
wa_dochdr-FISC_YEAR = l_gjahr."wa_hdr2-gjahr.
*IF wa_hdr-shkzg = 'H'.
* wa_dochdr-DOC_TYPE = 'KR'.
* elseif wa_hdr-shkzg = 'S'.
wa_dochdr-DOC_TYPE = 'KR'.
*endif.
wa_dochdr-ref_doc_no = wa_hdr2-ZRB_CRID."'Vendor A/C'.
endif.
sort it_accgl[] by ITEMNO_ACC.
sort it_curr[] by ITEMNO_ACC.
sort it_accgl1[] by ITEMNO_ACC.
sort it_curr1[] by ITEMNO_ACC.
l_error = 0.
if WRBTR is not initial.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
DOCUMENTHEADER = wa_dochdr
TABLES
ACCOUNTGL = it_accgl
ACCOUNTRECEIVABLE = it_cust
ACCOUNTPAYABLE = it_vend
ACCOUNTTAX = it_tax
CURRENCYAMOUNT = it_curr
CRITERIA = it_crit
RETURN = it_ret
ACCOUNTWT = it_wtax.
if no error found:
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER = wa_dochdr
IMPORTING
OBJ_KEY = wa_objkey
TABLES
ACCOUNTGL = it_accgl
ACCOUNTRECEIVABLE = it_cust
ACCOUNTPAYABLE = it_vend
ACCOUNTTAX = it_tax
CURRENCYAMOUNT = it_curr
CRITERIA = it_crit
RETURN = it_ret
ACCOUNTWT = it_wtax.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
.
Regards
Pankaj Mittal
‎2013 Jul 31 10:21 AM
Hi Adesh,
Before writing any code, create a test case data in SE37 .. So that it will be helpful to identify the any other problem while posting the document.
Regards
Pankaj Mittal