Skip to Content
Technical Articles
Author's profile photo Yogen Patil

ABAP CDS Views: Default values in parameters

Version: SAP S/4 HANA 1909


In SAP Embedded Analytics world ABAP Core Data Service Views also known as ABAP CDS Views. ABAP CDS Views are defined on top of existing database tables. Which can be further used in UI5 application for reporting purpose. When we deal with reports, then we need some selection parameters to restrict data in to get expected output. Which works as selection screen in UI5 application. Such functionality can be achieved with help ABAP CDS view.

Based on my experience & learning; I am drafting information in below article.

With continuation to previous article, let see how to get Default values in Parameters.

If we have customer requirement to develop a report having input prompts of date selection and we want to pass default values to prompts, then we can achieve this with help of CDS view.

Step 1: Create a CDS View with parameter.

In previous article I have shown how to create CDS view with Parameter – Link

Step 2: Assign default values to date parameter field.


If we use @Environment.systemField : #SYSTEM_TIME annotation then system date will be assigned to prompts.

What if we need previous day or first day of current month or first day of previous month in parameter as default value? Then same can be achieved by creating separate date bucket CDS view where we can calculate required dates.

    • Develop Date Bucket CDS View

      In below example, we have generated different dates which can be used to filter data dynamically.

      Output of CDS View

  • Date Bucket CDS view will be used in consumption view with help of Consumption.derivation annotations. This annotation enables derivation of the value for a parameter or a filter automatically at runtime by selecting a row from a given entity.

    Example –

    Now let’s execute our CDS view in RSRT to verify if we can get FirstDayOfPreviousMonth as default value in prompt.

  • RSRT Output


@AbapCatalog.sqlViewName: 'ZVM_C_CDSP'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@Analytics.query: true
@Analytics.dataExtraction.enabled: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS View With Parameter'
with parameters 
@Environment.systemField: #SYSTEM_DATE
@EndUserText.label: 'Todays Date'
@AnalyticsDetails.query.variableSequence: 1
@Consumption.hidden: true
p_keydate : abap.dats,
@AnalyticsDetails.query.variableSequence: 2
@Consumption.derivation: { lookupEntity: 'ZCDS_I_DATE_BUCKET',
resultElement: 'FirstDayOfPreviousMonth',
binding: [{ targetElement: 'CalendarDate', 
type:#PARAMETER , 
value: 'p_keydate' }]
P_ValidFrom : abap.dats
as select from ZCDS_WITH_PARAMETER
@AnalyticsDetails.query.axis: #ROWS
anlage as Installation,
@AnalyticsDetails.query.axis: #ROWS
bis as ValidTo,
@AnalyticsDetails.query.axis: #ROWS
ab as ValidFrom
} where ab >= $parameters.P_ValidFrom


Conclusion :

  • We can pass dynamic default values to input parameters based on CDS view.


Reference :

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Yasin M
      Yasin M

      very helpful. thanks Yogen for sharing.

      Author's profile photo Yogen Patil
      Yogen Patil
      Blog Post Author

      Welcome 🙂

      Author's profile photo Rosângela Regiani Jacomin Rabenhors
      Rosângela Regiani Jacomin Rabenhors

      Is it possible to create a variable default value, I need Current Month as a proposed value, in the the YYYYMM format. Any idea how i could do that?

      Author's profile photo Yogen Patil
      Yogen Patil
      Blog Post Author

      Yes it is possible.

      In above example we have used date bucket CDS view for deriving different dates. In this we have Calendar Year & Calendar month. We can use concat function to generate YYYYMM.

      concat(CalendarYear,CalendarMonth) as YYYYMM.
      Now you can use this value anywhere with below annotations
      @Consumption.derivation: { lookupEntity: 'ZCDS_I_DATE_BUCKET',
      resultElement: 'YYYYMM',
      binding: [{ targetElement: 'CalendarDate', 
      type:#PARAMETER , 
      value: 'p_keydate' }]

      I hope this will help you to resolve your issue.

      Author's profile photo Rosângela Regiani Jacomin Rabenhors
      Rosângela Regiani Jacomin Rabenhors

      Thanks Yogen,


      I an still confused on what I should put on the binding/target element parameter, what exactly is that?

      binding: [{ targetElement: 'CalendarDate'