Symptom (as described in SAP OSS Note 367175)
During the posting to accounting via BAPIs or IDocs you expect that analogous to posting transactions in FI the tax can be calculated. These are the following BAPIs / IDocs:
- BAPI_ACC_INVOICE_RECEIPT_POST
- BAPI_ACC_BILLING_POST
- IDoc message types ACLPAY, ACLREC, ACC_INVOICE_RECEIPT, ACC_BILLING
Additional key words
BAPI, IDoc, FB01, FB60
Cause and prerequisites
In general the calculation of taxes does not belong to the BAPI processing function. No other line item is generated after an FI/CO BAPI is called.
Explanation
So that tax can be calculated and posted correctly the SAP system requires far more information than just tax code, tax base amount and tax account. Transaction FB60 offers far more hidden information for the tax calculation, for example whether the net or gross amount should be used. In order to pass on all the necessary data to the BAPIs the interfaces would have to be oversized. In addition the implementation of a tax calculation function would cause the risk of possible inconsistencies in the posted tax amounts. Also it would not be possible to distinguish whether the taxes were calculated in the SAP system or in an external system (for example for an SD invoice for which the taxes are calculated in the external system).
Solution
A solution does not exist! The tax data must be determined before the BAPI is called and in the tax line items they must be passed on to the BAPI/IDoc.
My example code:
************************************************************************
* Calculate tax *
************************************************************************
DESCRIBE TABLE gt_curr_acc LINES gv_tax_tabix. ”No. of lines in currency table LOOP AT gt_inp_data INTO gs_inp_data.
gv_tax_tabix = gv_tax_tabix + 1. ”Actual tax line* Run calculation
CALL FUNCTION ’CALCULATE_TAX_FROM_NET_AMOUNT’
EXPORTING
i_bukrs = gs_inp_data-bukrs
i_mwskz = gs_inp_data-mwskz
i_waers = ’AUD’
i_wrbtr = lv_wrbtr
TABLES
t_mwdat = lt_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.
* Add your error handling here
* (CALL FUNCTION ’SWO_TEXT_FUNCTION_EXCEPTION’)
ENDIF.* Continue with processing => Tax acc table
CLEAR: ls_mwdat, gs_e1bpactx01.
READ TABLE lt_mwdat INTO ls_mwdat INDEX 1.
gs_e1bpactx01-itemno_acc = gv_tax_tabix.
gs_e1bpactx01-acct_key = ls_mwdat-ktosl.
gs_e1bpactx01-tax_code = gs_inp_data-mwskz.
gs_e1bpactx01-cond_key = ls_mwdat-kschl.CLEAR gs_edidd.
gs_edidd-segnam = zidoc_segnam-e1bpactx01.
gs_edidd-sdata = gs_e1bpactx01.
APPEND gs_edidd TO gt_tax_acc.* Currency acc table
CLEAR gs_e1bpaccr01.
gs_e1bpaccr01-itemno_acc = gv_tax_tabix.
gs_e1bpaccr01-currency = gs_inp_data-waers.
gs_e1bpaccr01-amt_base = gs_inp_data-wrbtr.
gs_e1bpaccr01-amt_doccur = ls_mwdat-wmwst.ENDLOOP.
