SAP VAT Tax Code ABAP SELECT Generator
Finance teams in African entities that run SAP often reconcile the VAT return to the ledger by exporting tax lines to Excel. This generator writes the ABAP SELECT statements for the common queries: tax code texts, tax lines for one code and period, and totals by tax code.
Fill in
Four character SAP company code.
Tax procedure (calculation schema) assigned to the country, for example TAXZA for South Africa.
One tax code, for example an input or output VAT code in your system.
Tax code texts for the procedure
REPORT zvat_by_tax_code.
DATA: lv_bukrs TYPE bukrs VALUE '1000',
lv_kalsm TYPE kalsm_d VALUE 'TAXZA',
lv_mwskz TYPE mwskz VALUE 'V1',
lv_from TYPE budat VALUE '20260901',
lv_to TYPE budat VALUE '20260930',
lv_spras TYPE spras VALUE 'E'.
" Tax code descriptions for the procedure
SELECT kalsm, mwskz, text1
FROM t007s
WHERE spras = @lv_spras
AND kalsm = @lv_kalsm
INTO TABLE @DATA(lt_codes).VAT lines for one tax code and period
" Tax lines posted in the period for the chosen tax code
SELECT bset~bukrs, bset~belnr, bset~gjahr, bset~buzei,
bset~mwskz, bset~shkzg, bset~hwbas, bset~hwste,
bkpf~budat, bkpf~blart
FROM bset
INNER JOIN bkpf
ON bkpf~bukrs = bset~bukrs
AND bkpf~belnr = bset~belnr
AND bkpf~gjahr = bset~gjahr
WHERE bset~bukrs = @lv_bukrs
AND bset~mwskz = @lv_mwskz
AND bkpf~budat BETWEEN @lv_from AND @lv_to
ORDER BY bkpf~budat, bset~belnr
INTO TABLE @DATA(lt_vat).Totals by tax code
" Summary of base and tax amount by tax code in the period
SELECT bset~mwskz,
SUM( bset~hwbas ) AS base_amount,
SUM( bset~hwste ) AS tax_amount
FROM bset
INNER JOIN bkpf
ON bkpf~bukrs = bset~bukrs
AND bkpf~belnr = bset~belnr
AND bkpf~gjahr = bset~gjahr
WHERE bset~bukrs = @lv_bukrs
AND bkpf~budat BETWEEN @lv_from AND @lv_to
GROUP BY bset~mwskz
ORDER BY bset~mwskz
INTO TABLE @DATA(lt_totals).
cl_demo_output=>display( lt_totals ).Verify table and field names in SE11 on your release. BSET holds tax data per document line in classic FI, and S/4HANA keeps it available, but check how your system stores tax data and whether authorization checks are required for production use. HWBAS and HWSTE are in local currency. Sign handling depends on SHKZG (debit or credit), so sum with care when reconciling to the VAT return. cl_demo_output is for quick checks in a sandbox only.
Want VAT reconciliation automated from SAP?
Optional: a read only reconciliation view that ties tax codes to return boxes, built on your own data.
Optional. The tool and every export work without this. No spam.
How to use it
Enter your company code, the tax procedure assigned to the country, the tax code you want to inspect and the posting date range. Copy the generated code into a new report in SE38 or into ABAP Development Tools, activate it in a development or sandbox client, and run it. The first block reads the text of each tax code from T007S. The second block joins BSET to BKPF to get the tax lines and posting date. The third block sums base and tax by code.
- Use a sandbox client first.
- Change dates in YYYYMMDD format.
- Add the document type filter if you want to exclude reversals or opening postings.
Where the data lives
BKPF is the accounting document header and holds posting date and document type. BSET holds tax data per document line, with the tax code in MWSKZ, the base amount in HWBAS and the tax amount in HWSTE. T007S stores tax code descriptions by language and tax procedure. The tax procedure in KALSM is assigned per country, and TAXZA is the standard procedure delivered for South Africa. Other African countries may use other delivered procedures or custom ones.
Reconciling to the VAT return
Run the totals block for the return period and compare each tax code to the matching box on the return, for example standard rated output, zero rated output and input tax. Differences usually come from manual journals, cut off dates, tax codes mapped to the wrong box, or reversed documents. Remember that the tax point on the return may differ from the posting date, so check how your return logic treats invoice date and payment date.
Common mistakes
Frequent errors include ignoring SHKZG so credit notes add instead of subtract, forgetting that foreign currency documents carry both local and foreign amounts, and running the report across all company codes. Do not build a production report straight from this snippet without authority checks and performance testing on large BSET volumes.
Frequently Asked Questions
Does this work on S/4HANA?
The table names are still available, but S/4HANA changes how accounting data is stored, and some customers prefer CDS views or the universal journal. Verify in SE11 and test in a sandbox before using the code in production.
What does TAXZA mean?
It is the tax procedure delivered for South Africa. A tax procedure defines the calculation schema for taxes in a country. Your system may use TAXZA or a copy, so check the assignment of your country in customizing.
Why are my totals different from the VAT return?
Common causes are manual journals, differing tax points, reversed documents, tax codes mapped to the wrong return box, and ignoring the debit credit indicator. Reconcile one tax code at a time to find the gap.
Can I use this for other African countries?
Yes, change the tax procedure and tax codes. The table logic is the same. Local requirements such as e-invoicing identifiers are held elsewhere, so this code covers ledger side reconciliation only.
If your VAT reconciliation still depends on manual exports, Netray can help build a read only reconciliation view over your SAP finance data, on-prem if required.
Related Tools
Africa Manufacturer Monthly Tax Compliance Checklist
A 32-point month-end checklist covering VAT, withholding tax, payroll taxes, customs and ERP data controls for a manufacturing entity in Africa.
Country & TaxAfrica Tax Authority and Tax ID Reference
Look up the revenue authority, the name of the tax ID and the headline VAT rate for 19 African countries when you set up vendor, customer and legal entity master data.
Country & TaxSouth Africa VAT 201 Reconciliation Worksheet
Compare output and input VAT in the ERP ledger with the amounts on each VAT 201 return and see the differences by period.
Developer ToolsERP Foreign Currency Revaluation SQL Generator
Generates SQL that picks the latest closing rate on or before the revaluation date, revalues open foreign currency items and summarises unrealised gain or loss by currency.