logo

Are you need IT Support Engineer? Free Consultant

Print Tax Code on Sales Order Confirmation Form by using Calculated Fields in SAP S/4HANA Cloud

  • By Sanjay
  • 01/09/2026
  • 35 Views



Background

SAP S/4HANA Cloud Public Edition delivers predefined print form templates for sales documents, e.g. order confirmation form for sales order. These templates cover the most common output fields out of the box. However, business requirements sometimes call for additional information that is not stored directly on the sales document item itself, but must be derived at runtime from related data such as pricing conditions.

We frequently receive requests from customers who want to print additional information on their sales document output forms but data is not exposed in the standard print form services. One example is the “Tax Code”, which is determined during pricing and stored on the pricing element, not on the sales document item, and is therefore not directly available in the standard form data model.

A natural first instinct is to read it from the released CDS view ‘I_SalesDocItemPricingElement'. However, customers sometimes worry that this approach will not work because the sales order has not yet been saved to the database at the time the form is generated.

In this blog, I will clarify this timing behavior and explain how “Calculated Fields” for output forms provide a clean, supported solution.

As described in the SAP Help topic Extensibility for Output Forms and Email Templates of Sales Documents, this feature relies on the “Data Source Extension” combined with  the “Cloud BAdI” implementation. Let's see how to use this feature to show the tax code on the sales order confirmation print form.

Business Example

Supply company XYZ operates across multiple countries and is required to print the applicable “Tax Code” on each sales order confirmation sent to customers. The tax code is determined during pricing via condition type “TTX1”. Company XYZ requires it to be printed explicitly, once per line item, in a dedicated section of the form. 

Since the tax code is not stored on the sales document item, a standard field extension or custom field approach will not work because there is no released API, CDS views could retrieve tax code from sales document buffer at runtime.

A calculated field populated at output generation time by reading pricing elements from the database can be considered as the right solution.

Key Timing Clarification: When Does the BAdI Fire?

Before diving into the implementation, it is important to understand a key aspect of how calculated fields work.

The Cloud BAdI “SD_SLS_FDP_ORDR_ITM_CALC” is called after the sales order is saved to the database. This means that by the time the BAdI logic runs, the sales order number is already persisted and all pricing conditions are available in the database. It is therefore perfectly valid to read the CDS view “I_SalesDocItemPricingElement” using the sales order number. 

There is one exception worth noting: in the sales order creation phase, when a user opens “form preview” of sales order creation screen, the calculated fields will not be populated in the form preview. This is expected behavior because the calculated field BAdI is not yet processed to update calculated field. The calculated fields are only filled in the actual output generated after the document is saved.

This distinction is important: the final output after save works correctly and completely. The preview limitation does not affect the output sent to customers.

Solution Overview

The solution involves four components:

  1. Data Source Extension with a Calculated Field defines a new item-level field “YY1_itemtaxcode” in the output data model for the sales order confirmation form
  2. Cloud BAdI “SD_SLS_FDP_ORDR_ITM_CALC” reads the tax code from CDS view I_SalesDocItemPricingElement after the sales order is saved, and populates the calculated field
  3. Custom Form Template adds the field to the print layout in a dedicated item-level section
  4. Configuration of Custom Form Template uploads the custom template and assigns it to the output type

Step 1: Create a Data Source Extension with a Calculated Field

Open the app “Custom Fields from the SAP Fiori Launchpad and navigate to the tab “Data Source Extensions. Create a new extension for the data source “Sales: Sales Order Confirmation Form”.

Zhaoyo_0-1788242510338.Png

Go to the tab “Calculated Fields”, create a new calculated field at item level by selecting the data source “SalesOrderItemExtensionType”, provide the BAdI implementation name and publish this data source extension.

Zhaoyo_1-1788242919126.Png

Step 2: Implement the Cloud BAdI

Once the data source extension is published, it is possible to directly click the BAdI implementation name to navigate to the BAdI implementation view. Or you can also find this BAdI implementation from the app “Custom Logic” and search for BAdI SD_SLS_FDP_ORDR_ITM_CALC.

This BAdI provides two key parameters:

  • it_entity_data: input table containing the sales order and item numbers for all items being output. Since the BAdI fires after the SO is saved, these document numbers are valid database keys that can be used to read any released CDS view.
  • ct_calculated_fields: CHANGING table where you set the calculated field values. The index of this table always matches the index of “it_entity_data”.

Implement following logic to retrieve pricing element from the CDS view I_SalesDocItemPricingElement and then map the tax code to the calculated field. 

* get tax code from price elements for all items
select sditem~salesorder,
sditem~salesorderitem,
price~taxcode
from i_salesorderitem WITH PRIVILEGED ACCESS as sditem
inner join i_salesdocitempricingelement WITH PRIVILEGED ACCESS as price
on sditem~salesorder = price~salesdocument
and sditem~salesorderitem = price~salesdocumentitem
inner join @IT_entity_data as item
on sditem~salesorder = item~salesorder
and sditem~salesorderitem = item~salesorderitem
where price~conditiontype=”TTX1″ and
price~taxcode <> ”
into table @DATA(lt_taxcodes).

* Calculate fields of your data source extension depending on e.g. sales order item
LOOP AT it_entity_data ASSIGNING FIELD-SYMBOL(<ls_sales_order_i>).
READ TABLE ct_calculated_fields ASSIGNING FIELD-SYMBOL(<ls_sales_order_i_calc>) INDEX sy-tabix. ” index-based relation
READ TABLE lt_taxcodes ASSIGNING FIELD-SYMBOL(<fs_taxcode>) WITH KEY salesorderitem = <ls_sales_order_i>-salesorderitem.
if sy-subrc = 0.
<ls_sales_order_i_calc>-yy1_itemtaxcode = <fs_taxcode>-taxcode.
endif.
ENDLOOP.

Don't forget to activate the BAdI implementation.

Step 3: Define Custom Form Template with Data Source Extension

Open the app “Maintain Form Templates” from the Output Management catalog. On the “Predelivered Templates” tab, find the Sales Order Confirmation template for your language and download it. Extract the “.zip” file and open the “.xdp” file in standalone application “Adobe LiveCycle Designer”. Please find detail in SAP Help.  

In the “Data View” panel, navigate to the item extension node, and the field “YY1_itemtaxcode” is visible after publishing in Step 1.

Zhaoyo_2-1788245028961.Png

Add a new section with same level alongside “ItemPriceConditions”, “ItemBatchNumber” and “ItemTextLines”, see example below:

Zhaoyo_4-1788245179455.Png

Put this custom field into the position after the table of price elements as a separate line. Make sure the field “YY1_itemtaxcode” is bound to the relevant data source extension node. 

Save the modified template with a special name, e.g. “YY1_SD_SLS_ORDER_CONFIRM_EXT.xdp”. 

Step 4: Upload and Assign the Custom Template

Open the app “Output Management Form Templates” and click the tab “Custom Templates”. Create a new custom template and click button “Upload” to upload custom form template which is modified in previous step.

Zhaoyo_6-1788247961425.Png

Then open the app “Manage Your Solution” and search for the configuration activity “Assign Form Templates” (102313). Create a new entry as below. 

Zhaoyo_7-1788248665688.Png

Then open the app “Output Parameter Determination” and go to the step “Form Template”, and assign this form template to the output parameter determination with special order reason “Z1”. 

Zhaoyo_8-1788250596077.Png

Save and activate the business rules. 

Business Process Testing

Test Case 1: Sales Order with Tax Condition TTX1

Create a sales order with the product TG11. The tax code is visible in the price elements view.

Zhaoyo_9-1788252323163.Png

Then save the sales order. 

Go to the tab “Output Items”, and click the link below to open the PDF form. 

Zhaoyo_12-1788252878389.Png

In the PDF form, the tax code is visible, see screenshot below.

Zhaoyo_13-1788252979255.PngConclusion

In this blog, I demonstrated how to use the calculated fields extensibility option in SAP S/4HANA Cloud Public Edition to print the tax code from pricing conditions on the sales order confirmation.

A key insight is that the Cloud BAdI “SD_SLS_FDP_ORDR_ITM_CALC” fires after the sales order is saved, which means the released CDS view I_SalesDocItemPricingElement is fully accessible using the document numbers from the BAdI input parameters.

The only limitation is that calculated fields are not populated in the form preview before save, which is expected behavior.





Source link

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat with us on WhatsApp!