Introduction
One of the recurring questions when implementing SAP Cloud ERP (SAP S/4HANA Cloud Public Edition) is how to address customer-specific business requirements while maintaining a clean core.
While standard business processes cover a wide range of requirements, local business practices sometimes require additional flexibility. In many cases, these requirements can be addressed by combining standard configuration with the extensibility capabilities available in SAP Cloud ERP.
In this blog, I would like to share a practical example from a customer engagement in Guatemala, where we addressed a specific procurement pricing requirement using extensibility.
The requirement was seemingly simple: allow purchasers to enter tax-inclusive prices (gross prices) when creating purchase orders instead of net prices.
Beyond the actual pricing requirement, this example demonstrates how key user extensibility and ABAP developer extensibility can be combined to exchange information between different Business Add-Ins (BAdIs) using a session buffer.
Let’s look at the business challenge, the solution, and how it can be implemented.
1. The Business Challenge
In many markets, suppliers communicate prices inclusive of taxes. Purchasing organizations negotiate and agree on these gross prices, and purchasers expect to enter the agreed amount directly when creating a purchase order.
In the standard procurement pricing process, however, the purchase price typically represents a net price, with applicable taxes calculated separately.
This creates an additional step for purchasers working with tax-inclusive supplier prices. Before entering a price into the purchase order, they may need to manually calculate the corresponding net amount.
Consider the following simplified example using an illustrative tax rate of 19%:
Pricing element | Amount |
Agreed supplier price including tax | 1,190.00 |
Applicable tax rate | 19% |
Net purchase price | 1,000.00 |
Tax amount | 190.00 |
Total amount including tax | 1,190.00 |
While the calculation itself is straightforward, performing it manually across numerous purchase orders and line items introduces unnecessary effort and potential errors, particularly when different quantities and rounding rules are involved.
The objective was therefore to allow purchasers to work with gross prices while enabling the system to automatically derive the corresponding net condition value.
An Additional Technical Challenge
The solution needs to support both gross and net pricing within the same procurement process. Consequently, the alternative condition amount calculation routine needs to know whether the purchaser has entered a gross or a net price.
To address this requirement, we introduced a custom tax code field at purchase order item level. Entering a tax code in this field indicates that the entered purchase price includes tax and that a gross-to-net calculation is required.
However, the purpose of this custom field in our implementation is not to dynamically determine the applicable tax rate. Since the customer scenario in Guatemala required only a single tax rate, the rate could be hardcoded directly in the calculation logic. The tax code entered in the custom field serves exclusively as a trigger for the gross-to-net calculation.
The challenge is that the custom field is not directly available through the interface of the alternative condition amount calculation BAdI.
This raises an interesting technical question:
How can we make information available to a BAdI when the required information is not part of its interface?
This is where the combination of key user extensibility, ABAP developer extensibility, and the use of a session buffer comes into play.
2. Solution Overview
Rather than introducing a separate procurement process or an external application, the requirement can be addressed directly within the existing pricing framework of SAP Cloud ERP.
The solution combines standard configuration, key user extensibility, and ABAP developer extensibility through the following components:
- A custom field at purchase order item level to capture the tax code for gross pricing.
- A custom ABAP class providing access to the session buffer, released for key user apps.
- A custom BAdI implementation to transfer the tax code into the session buffer.
- A custom purchasing condition type.
- A custom pricing BAdI implementation to retrieve the tax code and perform the gross-to-net calculation.
- An alternative condition amount calculation routine.
- A custom purchasing calculation schema.
Exchanging Information Between BAdIs Using a Session Buffer
The key technical element of the solution is the exchange of information between two different extension points:
BAdI | Purpose |
MM_PUR_S4_PO_MODIFY_ITEM | Reads the tax code from the custom purchase order item field and transfers it into the session buffer. |
PRCG_DOC_ITEM_CONDITION_AMOUNT | Retrieves the tax code from the session buffer and uses its presence to trigger the gross-to-net price calculation. |
A custom ABAP class is created using developer extensibility to provide access to the session buffer. By releasing this class for key user apps, it becomes available to the BAdI implementations created using the Custom Logic app.
When a purchaser enters a tax code in the custom field, the purchase order item modification BAdI reads the value and transfers it into the session buffer.
During pricing, the alternative condition amount calculation BAdI retrieves the tax code from the session buffer through the custom ABAP class.
Since the original customer scenario required only a single applicable tax rate, the rate was hardcoded directly in the pricing BAdI. The tax code retrieved from the session buffer is therefore used exclusively to determine whether the gross-to-net calculation should be performed.
The calculation logic distinguishes between two scenarios:
- Custom tax code field is empty: No gross-to-net conversion is performed, and the original condition amount is retained.
- Custom tax code field is populated: The gross-to-net calculation is performed using the predefined tax rate.
This allows both gross and net pricing scenarios to be supported within the same procurement process.
Gross-to-Net Calculation
The formula used to determine the net amount is:
Net amount = Gross amount / (1 + Tax rate)
For example, assuming a tax rate of 19%:
1,190 / 1.19 = 1,000
The standard tax calculation subsequently adds 190, resulting in the originally agreed gross amount of 1,190.
For illustration purposes, this blog uses a tax rate of 19%, rather than the tax rate applicable to the original customer scenario.
3. Implementing the Solution
The following steps describe how to implement the solution.
All condition types, identifiers, and routine numbers used in this example are illustrative and can be adapted to the customer’s environment.
Step 1: Create an ABAP Class for Session Buffer Access
Using ABAP Development Tools (ADT), create a custom ABAP class in the developer extensibility environment of SAP Cloud ERP.
The purpose of this class is to provide access to the session buffer, allowing information to be exchanged between the purchase order item modification BAdI and the pricing BAdI.
The class provides the functionality required to:
- Store the tax code in the session buffer.
- Retrieve the tax code from the session buffer during pricing.
Class example:
CLASS zcl_sapiens_buffer DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
CLASS-METHODS get_instance
RETURNING VALUE(ro_instance) TYPE REF TO zcl_sapiens_buffer.
METHODS:
set_tax_code IMPORTING iv_value TYPE char2,
get_tax_code RETURNING VALUE(rv_value) TYPE char2.
PROTECTED SECTION.
PRIVATE SECTION.
CLASS-DATA mo_instance TYPE REF TO zcl_sapiens_buffer.
DATA mv_value TYPE char2.
ENDCLASS.
CLASS zcl_sapiens_buffer IMPLEMENTATION.
METHOD get_tax_code.
rv_value = mv_value.
ENDMETHOD.
METHOD get_instance.
IF mo_instance IS NOT BOUND.
mo_instance = NEW #( ).
ENDIF.
ro_instance = mo_instance.
ENDMETHOD.
METHOD set_tax_code.
mv_value = iv_value.
ENDMETHOD.
ENDCLASS.
Once the class has been implemented and activated, it must be released for use in key user apps.
This step is essential because both BAdI implementations will be created using key user extensibility in the Custom Logic app and need to access the functionality provided by the custom ABAP class.
This is a practical example of how developer extensibility can provide reusable technical functionality that can subsequently be consumed by key user extensions.
Step 2: Create a Custom Tax Code Field
Open the Custom Fields app and create a custom field in the purchasing document item business context.
Enable the field for the relevant purchase order application and publish it.
The purpose of this field is to allow purchasers to indicate that they are working with a tax-inclusive price.
From a business user perspective, the process is straightforward:
- Net pricing scenario: The custom tax code field remains empty.
- Gross pricing scenario: The purchaser enters the applicable tax code in the custom field.
In the current implementation, the presence of a tax code in this field serves as the trigger for the gross-to-net calculation. It is not used to determine the tax rate dynamically.
Step 3: Implement the Purchase Order Item Modification BAdI
Open the Custom Logic app and create an implementation for the following BAdI:
MM_PUR_S4_PO_MODIFY_ITEM
When the purchaser enters a value in the custom tax code field, the purchase order item modification BAdI is triggered as part of item processing.
Within the BAdI implementation, read the tax code from the custom field and use the previously created ABAP class to transfer the value into the session buffer.
The tax code is now available for retrieval by the alternative condition amount calculation BAdI during pricing.
Particular attention should be paid to scenarios in which a purchaser changes or removes the tax code, as well as purchase orders containing multiple items with a combination of gross and net prices.
Step 4: Create a Custom Condition Type
In SAP Central Business Configuration (CBC), navigate to the configuration activity:
Define Condition Types – Set Pricing Condition Types
Create a custom condition type by copying an existing standard price condition type, such as PPR0.
For this example, we use:
- Reference condition type: PPR0
- Custom condition type: ZPR0
The remaining condition type settings can initially be retained from the reference condition type.
The custom condition type will be used to support gross price entry in the purchasing process.
Step 5: Implement the Custom Pricing Logic
Open the Custom Logic app in the SAP Fiori launchpad and create a new implementation using the following BAdI:
Define Alternative Calculation of Condition Amount in Document Item
Technical name:
PRCG_DOC_ITEM_CONDITION_AMOUNT
This extension point allows us to implement an alternative calculation of the condition amount at document item level.
Create an implementation and assign a custom formula identifier, for example, 990.
The identifier is important because it will subsequently be used to connect the BAdI implementation to the pricing routine.
Within the BAdI implementation, use the custom ABAP class to retrieve the tax code previously stored in the session buffer.
The calculation logic follows these steps:
- Retrieve the tax code from the session buffer.
- Check whether a tax code has been provided.
- If a tax code is available, calculate the net condition amount using the hardcoded tax rate.
- Return the calculated net condition amount to the pricing framework.
Since the original customer requirement involved only a single applicable tax rate, there was no need to implement dynamic tax rate determination. This keeps the implementation relatively simple.
For example, using a hardcoded tax rate of 19%, the gross amount is divided by 1.19 to determine the net condition amount.
Step 6: Configure the Alternative Calculation Routine
Return to SAP Central Business Configuration and navigate to:
Set Alternative Calculation of Condition Amount
Create a new routine number, for example:
3000006
Select the newly created routine and navigate to Assign Enhancement IDs to a Routine Number.
Maintain the relevant process enhancement option task and assign the enhancement identifier defined in the BAdI implementation.
In our example, this is identifier 990.
This configuration establishes the connection between the pricing procedure and the custom pricing logic implementation.
Step 7: Configure the Purchasing Calculation Schema
Navigate to the Calculation Schema configuration activity for purchasing.
Create a custom calculation schema by copying an existing standard schema appropriate for the procurement process.
Within the control data of the calculation schema:
- Add the custom condition type ZPR0.
- Assign an appropriate step number, for example, 61.
- Position the condition type appropriately within the pricing sequence.
- Maintain the relevant subtotal settings.
- Assign routine 3000006 in the column Alternative Calculation of Condition Amount.
The position of the custom condition type within the calculation schema is important, particularly when additional discounts, surcharges, or logistics costs are involved.
The pricing procedure must also be configured so that the standard and custom price conditions do not result in the purchase price being counted twice.
Step 8: Update Calculation Schema Determination
Navigate to the configuration activity:
Determination of Calculation Schema in Purchasing
Assign the newly created calculation schema to the relevant schema determination settings.
This ensures that the custom pricing procedure is applied to the intended purchasing scenarios.
Depending on the customer’s requirements, the solution can be restricted to specific purchasing scenarios rather than changing the pricing behavior for all procurement transactions.
4. Testing the Solution
Once the configuration and custom logic have been completed, create a purchase order using the Create Purchase Order – Advanced app.
Enter the relevant supplier, material, quantity, and purchase price.
For a gross pricing scenario, enter the applicable tax code in the custom purchase order item field. For a standard net pricing scenario, leave the custom field empty.
Consider the following example comparing both scenarios using the same entered unit price and an illustrative tax rate of 19%:
Pricing element | Net pricing scenario | Gross pricing scenario |
Purchase order quantity | 10 | 10 |
Entered unit price | 119.00 | 119.00 |
Custom tax code field | Empty | Populated |
Gross-to-net calculation | No | Yes |
Net unit price | 119.00 | 100.00 |
Net order value | 1,190.00 | 1,000.00 |
Applicable tax rate | 19% | 19% |
Tax amount | 226.10 | 190.00 |
Total including tax | 1,416.10 | 1,190.00 |
In the gross pricing scenario, the following process takes place behind the scenes:
- The purchaser enters the agreed gross price and a tax code in the custom field.
- The purchase order item modification BAdI reads the tax code and transfers it into the session buffer.
- The alternative condition amount calculation BAdI retrieves the tax code from the session buffer.
- The presence of the tax code triggers the gross-to-net calculation using the hardcoded tax rate.
- The calculated net condition amount is returned to the pricing framework.
- The standard tax calculation determines the tax amount based on the calculated net value.
If the custom tax code field remains empty, no gross-to-net conversion is performed.
The purchaser can therefore enter the agreed gross price without having to manually calculate the net amount, while the standard net pricing process remains available.
The validation should not stop at purchase order creation. It is equally important to test the downstream procurement and financial processes, including goods receipt, supplier invoice processing, and financial postings, where applicable.
5. Considerations for a Productive Implementation
The example described in this blog demonstrates the underlying extensibility concept. Depending on the customer’s business requirements, additional considerations may need to be addressed.
Session Buffer Management
When using a session buffer to exchange information between BAdIs, it is important to ensure that the correct information is available at the time of calculation.
Relevant test scenarios include:
- Purchase orders containing multiple items.
- Purchase orders containing both gross and net pricing items.
- Changes to or removal of the custom tax code.
- Repeated pricing calculations.
- Reopening and changing existing purchase orders.
- Creating multiple purchase orders within the same session.
The session buffer should be treated as temporary runtime storage rather than persistent storage for business information.
Supporting Multiple Tax Rates
In the original customer scenario in Guatemala, only a single tax rate needed to be considered. Consequently, the tax rate was hardcoded in the alternative condition amount calculation BAdI.
However, customers operating across multiple countries or purchasing products subject to different tax rates may require a more flexible solution.
One advantage of transferring the actual tax code into the session buffer, rather than simply using a Boolean indicator for gross pricing, is that the existing approach could be extended to support dynamic tax rate determination.
Potential options include:
- Retrieving tax information through suitable released CDS views, subject to availability.
- Maintaining tax code and tax rate mappings using a custom business object.
Regardless of the approach selected, the tax rate used for the gross-to-net conversion must be consistent with the rate used by the standard tax calculation.
These enhancements were not required for the original customer scenario but illustrate how the solution could be extended to address more complex requirements.
Rounding Differences
Reverse calculation of tax-inclusive prices can introduce rounding differences, particularly when working with multiple quantities or unit prices containing several decimal places.
For example, an agreed gross amount of 820.00 could result in a calculated amount of 820.06 due to differences in rounding.
Depending on the requirements, these differences could be addressed by enhancing the custom calculation logic or introducing additional rounding conditions.
Discounts, Surcharges, and Logistics Costs
The sequence in which discounts, surcharges, freight costs, and other pricing conditions are applied can influence the final calculation.
These scenarios should be evaluated individually to ensure that the calculation schema reflects the customer’s commercial agreements and applicable tax requirements.
6. Why This Is a Good Example of Clean Core Extensibility
What makes this example particularly interesting is the combination of three complementary capabilities available in SAP Cloud ERP.
Capability | Purpose in the solution |
Standard configuration | Condition types, pricing routines, calculation schemas, and schema determination |
Key user extensibility | Custom tax code field and implementations of the two BAdIs |
ABAP developer extensibility | Custom ABAP class providing access to the session buffer |
By releasing the custom ABAP class for key user apps, functionality developed using ABAP developer extensibility can be consumed directly by key user extensions.
This allows us to overcome a limitation in the information available within an individual BAdI interface without modifying SAP standard code.
The session buffer provides a mechanism for exchanging the required information between different extension points within the business process.
While the use case described in this blog focuses on gross pricing in procurement, the underlying extensibility pattern may also be relevant to other scenarios where information needs to be exchanged between extension points, provided their execution context and lifecycle support this approach.
Conclusion
Gross pricing in procurement is a relatively simple business requirement, but it is a good example of how local business practices can create challenges during an ERP implementation.
By combining standard pricing configuration, key user extensibility, and ABAP developer extensibility, we can address the requirement while retaining the standard procurement framework.
More importantly, this example demonstrates that the different extensibility capabilities available in SAP Cloud ERP should not necessarily be considered in isolation. Combining them can open up additional possibilities for addressing customer-specific business requirements while maintaining a clean core.