If you want to post billing documents or invoice receipts by using the BAPI „BAPI_ACC_DOCUMENT_POST“ it will become necessary to use tax codes. The tax codes on sales and purchases represents a tax category that will be declared for tax reporting to the tax authorities. Tax codes are unique per country and are stored in table T007A.
A tax procedure specifies the conditions that are allowed for a document and defines the sequence in that they are used.
The tax procedure needs to be assigned to the country code by customizing.
The tax code maintenance can be done by transaction FTXP here the user can change the description, tax percentage rates and the general ledger account that is assigned to the tax code. In addition to that a tax category needs to be assigned to the control data on a G/L account (transaction FS00).
The general useage of BAPI „BAPI_ACC_DOCUMENT_POST“ already mentioned by a previous blog post. But how to post the correct tax information when using that BAPI. In this example we want to post an invoice that isnt proceeded by SAP SD. We assume that we got the invoice information by an external billing system by .csv/.txt file. We are simulating an interface processing and want to post following information:
1) customer open item (accounts receivable)
3) output tax of 19%.
We assume that the invoice interface file would have net amounts that doesn’t include the tax amount yet. The field header structure would be:
date; itemtxt; net amount; customer
To post tax amounts within BAPI_ACC_DOCUMENT_CHECK/BAPI_ACC_DOCUMENT_POST it is required to use the internal table ACCOUNTTAX. Unfortunately the BAPI documentation isnt very helpful about the proper use here. If you create a line of accounttax information it is required to add a line of currencyamount for this tax information. Otherwise the BAPI will return an error message that the structure is incomplete and data is missing.
A useful function module to determine the correct tax amount, tax account and addional tax information to fill this accounttax line is to run CALCULATE_TAX_FROM_NET_AMOUNT for net amount scenario. (otherwise CALCULATE_TAX_FROM_GROSSAMOUNT) We need to import the tax code, company code and the amount. The function module returns the tax information in the internal table T_MWDAT that becomes useful for filling the accounttax later.
The following fields needs to be added for the accounttax and currencyamount internal table. Both lines needs to be assigned to the same itemno_acc (line item in the posting).
So the overall importing data to the BAPI should look like this: (for each posting)
WA_DOCUMENTHEADER (1x document header information)
ITAB_ACCOUNTGL (1x revenue line)
ITAB_ACCOUNTRECEIVABLE (1x customer open item (accounts receivable))
ITAB_ACCOUNTTAX (1x tax account line)
ITAB_CURRENCYAMOUNT (for each of these line items we need the amount information and connected by the same itemno_acc that they refer to)
If the return table of BAPI „BAPI_ACC_DOCUMENT_CHECK“ doesn’t show any errors the produtive run by using BAPI_ACC_DOCUMENT_POST can be performed.
The return table contains the document numbers that got posted by the BAPI.