Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
yogen_patil
Explorer
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
11 Comments
Labels in this area