‎2006 Oct 12 8:16 AM
I want to known how to post document with tax items.
How to get values for tax structure if we only know tax code for account.
‎2006 Oct 12 8:31 AM
Hi Amit,
Take a look at the following code :
DATA : w_compt(8) TYPE n. " This is the line N°
* You have to put the corresponding one in
* accountpayable/accountgl
......
w_compt = w_compt + 1.
PERFORM fill_account_tax USING w_compt
CHANGING w_tax_amount.
......
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = documentheader
IMPORTING
obj_type = l_type
obj_key = l_key
obj_sys = l_sys
TABLES
accountgl = accountgl
accountpayable = accountpayable
currencyamount = currencyamount
accounttax = accounttax
extension1 = extension1
return = return.
.....
*&--------------------------------------------------*
*& Form fill_account_tax
*&--------------------------------------------------*
FORM fill_account_tax USING p_compt CHANGING p_tax_amount.
* ACCOUNTTAX
PERFORM calculate_vat_amount USING t_notilus-comp_code
t_notilus-vat_cod
t_notilus-amt_doccur
CHANGING p_tax_amount
accounttax-tax_code
accounttax-tax_rate
accounttax-acct_key
accounttax-gl_account
accounttax-cond_key.
accounttax-tax_date = sy-datum.
accounttax-itemno_acc = p_compt.
accounttax-itemno_tax = p_compt - 1.
APPEND accounttax.
ENDFORM. " fill_account_tax
*&-------------------------------------------------*
*& Form calculate_vat_amount
*&-------------------------------------------------*
FORM calculate_vat_amount USING p_comp_code
p_vat_cod
p_amount
CHANGING tax_amount
w_vat_cod
w_msatz
w_ktosl
w_hkont
w_kschl.
DATA : BEGIN OF t_mwdat OCCURS 0.
INCLUDE STRUCTURE rtax1u15.
DATA : END OF t_mwdat.
DATA : w_ttc LIKE bseg-wrbtr.
w_ttc = p_amount.
CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
EXPORTING
i_bukrs = p_comp_code
i_mwskz = p_vat_cod
i_waers = 'EUR'
i_wrbtr = w_ttc
TABLES
t_mwdat = t_mwdat
EXCEPTIONS
bukrs_not_found = 1
country_not_found = 2
mwskz_not_defined = 3
mwskz_not_valid = 4
ktosl_not_found = 5
kalsm_not_found = 6
parameter_error = 7
knumh_not_found = 8
kschl_not_found = 9
unknown_error = 10
account_not_found = 11
txjcd_not_valid = 12
OTHERS = 13.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR t_mwdat.
READ TABLE t_mwdat INDEX 1. "INTO s_mwdat
* w_tax_amount = t_mwdat-WMWST.
w_tax_amount = t_notilus-vat_amount.
w_ktosl = t_mwdat-ktosl.
w_hkont = t_mwdat-hkont.
w_kschl = t_mwdat-kschl.
w_msatz = t_mwdat-msatz.
w_vat_cod = p_vat_cod.
ENDFORM. " calculate_vat_amount
Hope this helps,
Erwan
‎2006 Oct 12 8:31 AM
Hi Amit,
Take a look at the following code :
DATA : w_compt(8) TYPE n. " This is the line N°
* You have to put the corresponding one in
* accountpayable/accountgl
......
w_compt = w_compt + 1.
PERFORM fill_account_tax USING w_compt
CHANGING w_tax_amount.
......
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = documentheader
IMPORTING
obj_type = l_type
obj_key = l_key
obj_sys = l_sys
TABLES
accountgl = accountgl
accountpayable = accountpayable
currencyamount = currencyamount
accounttax = accounttax
extension1 = extension1
return = return.
.....
*&--------------------------------------------------*
*& Form fill_account_tax
*&--------------------------------------------------*
FORM fill_account_tax USING p_compt CHANGING p_tax_amount.
* ACCOUNTTAX
PERFORM calculate_vat_amount USING t_notilus-comp_code
t_notilus-vat_cod
t_notilus-amt_doccur
CHANGING p_tax_amount
accounttax-tax_code
accounttax-tax_rate
accounttax-acct_key
accounttax-gl_account
accounttax-cond_key.
accounttax-tax_date = sy-datum.
accounttax-itemno_acc = p_compt.
accounttax-itemno_tax = p_compt - 1.
APPEND accounttax.
ENDFORM. " fill_account_tax
*&-------------------------------------------------*
*& Form calculate_vat_amount
*&-------------------------------------------------*
FORM calculate_vat_amount USING p_comp_code
p_vat_cod
p_amount
CHANGING tax_amount
w_vat_cod
w_msatz
w_ktosl
w_hkont
w_kschl.
DATA : BEGIN OF t_mwdat OCCURS 0.
INCLUDE STRUCTURE rtax1u15.
DATA : END OF t_mwdat.
DATA : w_ttc LIKE bseg-wrbtr.
w_ttc = p_amount.
CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
EXPORTING
i_bukrs = p_comp_code
i_mwskz = p_vat_cod
i_waers = 'EUR'
i_wrbtr = w_ttc
TABLES
t_mwdat = t_mwdat
EXCEPTIONS
bukrs_not_found = 1
country_not_found = 2
mwskz_not_defined = 3
mwskz_not_valid = 4
ktosl_not_found = 5
kalsm_not_found = 6
parameter_error = 7
knumh_not_found = 8
kschl_not_found = 9
unknown_error = 10
account_not_found = 11
txjcd_not_valid = 12
OTHERS = 13.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR t_mwdat.
READ TABLE t_mwdat INDEX 1. "INTO s_mwdat
* w_tax_amount = t_mwdat-WMWST.
w_tax_amount = t_notilus-vat_amount.
w_ktosl = t_mwdat-ktosl.
w_hkont = t_mwdat-hkont.
w_kschl = t_mwdat-kschl.
w_msatz = t_mwdat-msatz.
w_vat_cod = p_vat_cod.
ENDFORM. " calculate_vat_amount
Hope this helps,
Erwan
‎2006 Oct 12 3:23 PM
‎2006 Oct 12 8:47 AM
Hi Amit!
You would need to
- read the tax percentages to the tax codes
- summarize the tax base amounts (net values of your doc) grouped by the different tax codes
- calculate the tax amounts for each tax code
- distribute the tax amount to the different positions
This can lead to two identical net values with different gross values because of this special rounding rule.
I would never make such a calculation on my one - for this SAP documents and document pricing is for.
Maybe you create a dummy document to get the correct values and delete this afterwards - it's much saver in general, you would need a lot of coding to cover all exceptions otherwise.
Regards,
Christian
‎2006 Nov 14 1:34 PM
Hi Erwan,
I need help because i can't see the tax line item in the document posted....
I'm doing exactly what you were posted, and it works fine....... but then, when the document were posted, I try to see it by FB03 and what happend ?
the document sould be had 3 line items:
1- (01) ACCOUNTRECEIVABLE ITEM ---> 100 $
2- (50) GL ITEM ---> 82.65 $
<b>3 -(50) TAX ITEM ---> 17.35 $</b>
But if i see the document by fb03, i just see 2 lines:
1- (01) ACCOUNTRECEIVABLE ITEM ---> 100 $
2- (50) GL ITEM ---> 100 $
and if I push the "tax" button, i see the tax item correctly (amount 17.35 $ and BASE = 82.65), Even in BSET the tax line item exists.
Also if i post the document manually, i can see the three line items......
Any Help ?
PD: My english is not the best, sorry.
Thanks
‎2006 Nov 28 3:35 PM
Hi, I am using the same BAPI trying to post an AP invoice with tax with jurisdiction codes. Thanks for the tip re the function module to calcuate the tax. It seems when posting using jurisdiction codes, all levels need to be provided in the IDOC with the condition types etc rather than as per FB01 or FB60 where you just enter the jurisdiction code and SAP determines the rest?
Thanks
Pritesh