Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Krithik
Explorer
0 Likes
491

How to Write CDS Table Functions the Standard SAP Way

In SAP S/4HANA, we cannot always express complex business logic using pure CDS syntax. To manage scenarios like long text processing, procedural calculations, or important joins, SAP uses CDS Table Functions implemented through AMDP.

While many developers create table functions on the fly, SAP sticks to a strict and consistent design pattern across its standard content. This approach ensures good performance, readability, upgrade safety, and transportability.

A useful way to grasp this standard is to look at how SAP builds transactional CDS views, especially those that use CDS Table Functions. By examining SAP-delivered objects like I_SalesOrderTP, we can clearly see the structure, naming conventions, annotations, and implementation method that SAP expects developers to follow.

This guide explains how SAP writes table functions, how they implement them using AMDP, and how they use them in CDS views. This will help you design your own extensions in the same way SAP does.

  1. Start with a Standard View: I_SALESORDERTP.
  • SAP provides many standard CDS views in S/4HANA.
  • To understand how SAP writes table functions, the easiest example is the view: I_SALESORDERTP
  • This is a Transactional Processing View, delivered by SAP.

2025-11-27_19h51_30.png

   2. Locate the Table Function Used Inside the View.

  • Inside the view, you will notice SAP has used: with parameters (...).

2025-11-27_19h53_17.png

  • This indicates that the view is consuming a CDS Table Function.

        3. You will find the CDS Table Function that SAP has written.

2025-11-27_19h53_23.png

    4.  Open the AMDP Class to See SAP’s Logic.

  • Once you find the Table Function name, open the AMDP class: cl_sd_S4h_stxl_utils=>get_header_text
  • Inside this class, SAP has written the entire logic.

2025-11-27_19h53_43.png

When crafting Table Functions ", in the manner SAP does " consistently adhere to this structure:

Create a CDS Table Function with parameters.

Implement it via an AMDP class/method using native SQLScript.

Consume it in your final CDS view using with parameters.

Follow the exact naming, annotation, and structure shown in standard objects such as I_SalesOrderTP, I_PurchaseOrderTP, I_BillingDocumentTP, etc.

Following this pattern guarantees:

Best performance (native HANA execution)

Transportability and upgrade-safety

Consistency with thousands of standard SAP-delivered objects

Conclusion

It is a tried-and-true architectural best practice to use SAP's standard pattern for CDS Table Functions. You can align your custom developments with the same design principles used in core SAP objects like *I_SalesOrderTP*, *I_PurchaseOrderTP*, and *I_BillingDocumentTP* by defining a CDS Table Function with parameters, implementing its logic in an AMDP method using native SQLScript, and consuming it through a final CDS view.


This method guarantees that sophisticated logic runs directly on SAP HANA for maximum efficiency, stays neatly isolated from the consumption layer, and is resilient to upgrades and transports. More significantly, because it adheres to a well-known and extensively used standard, it makes your solution instantly comprehensible to other SAP developers.