How to derive dynamic text label in CDS view with value lookup
Share

Background:

Recently I got a requirement to create an account payable aging report which contains dynamic text based on user input, for example, user input aging interval as: 30, 60, 90. in the output of the report, the required report format will be:

Customer Due in 30 days Due in 31-60 days Due in 61-90 days Due 91+ days
1001 $300 $600 $900 $1200

In the traditional SAP BW world, this can be easily achieved by Text variable, however in SAP CDS view, dynamic text is not available in early versions. In my current system version, the version is ABAP 7.58, and it supports this annotation very well.

Solution:

So instead of going this complex scenario, I will use a simple SAP data source:  SFLIGHT to achieve the similar requirement.

Scenario explanation:

There will be only one base measure called Airfare, based on the user input: number of Days X, the output will show the AirFare, X Days AirFare, X+1 Days AirFare, the highlighted two columns text will be dynamically derived based on the user input

Year Month AirFare 10 Days AirFare 11 Days AirFare
02.2023 $300 $600 $900

This is how the end to end implementation work look like

  • Define a helper view: this is to return the day + 1

Screenshot 2025-10-26 222644.png

  • Define cube level data model, with base fare, base fare * input days, base fare * input days + 1, the measure if purely for distingush the different dollar value

Screenshot 2025-10-26 222815.png

  • Comes with the fun part, in the query view, we define the parameter which populate the derived dayPlus1 using lookup view which defined in first step:

Screenshot 2025-10-26 223038.png

  • In the measure column, wewill appy the dynamic text using annotation: @Consumption.dynamicLabel:

Screenshot 2025-10-26 223154.png

Now Let’s run the CDS view from BW query, as you can see user will be prompt to fill input days (default value is 10):

Screenshot 2025-10-26 223255.png

The measure column will derive the text dynamically based on user input and helper view:

Screenshot 2025-10-26 223352.png

 

With the help to combine annotation @Consumption.dynamicLabel and @Consumption.derivation.lookupEntity, we will be able to achieve the same requirement in the BW world by using Text variable and custom exit. 

I hope this blog give you some help with the how dynamic text can be implemented using SAP CDS view, if you have any questions, please feel free to leave a message. 

 

 

 

 

  Read More Technology Blog Posts by Members articles 

#abap

By ali