Documentation Reduction Logic
- Sergio Cannelli
- Jun 27
- 2 min read
This article provides a detailed explanation of a specific ABAP code segment that performs a reduction operation on tax-related data structures within an SAP environment.
Overview
The code defines a TABLE named CH_TL_UNIV_CINCO using a REDUCE expression on a collection of tax-related data structures. The purpose is to aggregate and transform information about taxes and bases extracted from two internal tables (TL_IMPUESTODES and TL_COMPLEMENTO), filtered by specific criteria.
This operation is useful in financial processes where comparatives between original and new tax values are computed, possibly for reporting or adjustment purposes.
Detailed Explanation
CH_TL_UNIV_CINCO Constant
This TABLE is initialized using the REDUCE operator with the type ZIF_VARIANTE_KERNEL_BADI1~TYT_IMPUESTO. The REDUCE expression iterates over a filtered subset of the TL_IMPUESTODES internal table, which is accessed using the index KEYCOMP6. The filtering conditions are based on matching three fields:
ID = ZZIDCARGA
BELNR = ZZBELNR
ZUONR = ZZUONR
For each filtered entry (S_FACTURA), a nested iteration occurs over TL_COMPLEMENTO — again using the same key but filtered by matching the fields to those in S_FACTURA. In each nested iteration (S_FACTURA1), a new element is appended to the result set with specific transformed values.
Field-by-Field Mapping and Logic
ID
Copied directly from S_FACTURA1-ZZIDCARGA, representing an identifier for the record.
ZZBELNR
Document number, copied from S_FACTURA1-ZZBELNR.
MWSK1
Tax indicator, sourced from S_FACTURA1-ZZIND_IMP.
ZUONR
Assignment number, taken from S_FACTURA1-ZZUONR.
ZZBASE_RV
Original base amount from the document: S_FACTURA1-ZZBASEORIGINAL.
ZZBASE_NEW_SP
New base amount (possibly a new tax or adjustment stage): S_FACTURA-ZZBASE.
ZZTAX_RV
Original tax amount from the document: S_FACTURA1-ZZIMPUESTO_ORIG.
ZZTAX_NEW_SP
Tax amount to be created in the SP stage: S_FACTURA-KWERT.
ZZBASE_UNI5
Represents the absolute difference between the new base and the original base, ensuring it is never negative. This is calculated using a conditional operation:
If (S_FACTURA-ZZBASE - S_FACTURA1-ZZBASEORIGINAL) is less than zero, multiply by -1 to get the absolute value.
Otherwise, keep the positive difference as is.
The result is converted to the type ZR2R_CALCULO_P. This field is described as "BASE UNIVERSOS 5", possibly a special categorization of base amounts.
ZZTAX_INI5
Similar to ZZBASE_UNI5, this field calculates the absolute difference between the new tax and the original tax, using conditional logic and converted to ZR2R_CALCULO_P. It is labeled as "IMPUESTO UNIVERSO 5", indicating its relevance to a particular tax classification or universe.
KTOSL
Condition code or grouping key, taken from S_FACTURA1-ZZCONDICION.
Conceptual Flow and Use Cases
This code effectively merges and compares two data sources filtered by matching identifiers. It then constructs a collection of records highlighting differences between original and newly computed tax bases and tax amounts.
A practical use case might involve financial reconciliations or validations where adjustments are needed based on differences between prior recorded tax data and current computations.
Example Usage.
Suppose:
The tables TL_IMPUESTODES and TL_COMPLEMENTO contain tax calculation data for invoices.
The relevant records are filtered by ID, BELNR, and ZUONR representing load, document, and assignment numbers respectively.
After executing the reduction, CH_TL_UNIV_CINCO will contain processed items including the differences between new and original tax bases and taxes, calculated safely as positive values.
This constant can then be used downstream for reporting, further calculations, or posting adjustments.
Written to assist developers who want to understand tax data transformations in the SAP ABAP environment.
Code
Comments