Technical Articles
ABAP CDS Views: Default values in parameters
Version: SAP S/4 HANA 1909
Introduction:
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
@VDM.viewType: #CONSUMPTION
@Analytics.query: true
@Analytics.dataExtraction.enabled: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS View With Parameter'
define view ZCDS_C_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 : help.sap.com
very helpful. thanks Yogen for sharing.
Welcome 🙂
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?
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.
I hope this will help you to resolve your issue.
Thanks Yogen,
I an still confused on what I should put on the binding/target element parameter, what exactly is that?
Hi Yogen,
I have create a CDS view and given the annotation @Analytics.publish : true, but when I tried opening the query by adding prefix 2C to my sql view, the query is not available there.
Can you let us know how we can activate the Query.
Go to properties - API state - release
Hi Yogen,
Nice Blog!!
Can we pass the dynamic value for the parameter based CDS view when used in OData Service ?
We are trying to generate OData service on top of Parameter based CDS view , we need to assign
default value for the parameter in view itself is it possible ?
Hi Yogen,
very informative! any chance you would know how to map the result value to a field which has #INTERVAL selection type (low and high) values? as of now i am only able to pass to low value.
Thanks and more power!
Rowie
Hi Yogen,
Like in your example,
Please note that if i make use of the similar kind of CDS and create an Overview page, with the global filter, the input fields are not filled with the default value. (current date)
This works fine with Eclipse ADT -> Preview, but when consume the same CDS code in the Fiori Elements overview page, the default value is not populated and we need to input the current date manually.
Our requirement is to have this current date filled by default using the SYSTEM_DATE.
Even the derivation (Calling a CDS and get that output field and pass it as input) also not working when we consume the CDS from the Fiori Elements side.
Appreciate your support if you can provide some input on this.
Thanks,
Hi Mohammad Wasim Hunachangi,
I also have similar requirement, did you find any solution for it.
I have created CDS based BOPF, I have deploy application using WebIdE as Fiori List element. While Creating new entry I want to default Logon user and display it on identification screen.
I tried with determination but wont get option to select LOAD as trigging point.
If I select category as React After Modification, it store update correctly in backend.
But my requirement is to show value before saving.
Thanks In Advance