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: 
kumarsanjeev
Explorer
In the previous blog post, we saw simple examples of CDS views which are a type of a select statement and you could surely add ‘WHERE’ clause to filter the data.  But this where clause is static with a non-parameterized view and may not fulfill the project requirements where a user interaction is required.  So it is absolutely possible to add ‘Parameters’ to take user input and filter out the data from the CDS view accordingly;

 

  1. Create a new CDS view;




 

You can choose the parameter template for easy code;



 

This is what we get as the default structure of the CDS view with Parameters.  Look at the ‘with parameters’ clause got added.



 

2. Add the SQL view name and table name. To the ‘with parameters’ clause, add the parameter name before colon and the data type after colon as mentioned above.  For ‘Data Type’ you can either add the data element directly as we used to do in classic ABAP to declare a variable i.e. or you can add primitive data type like abap.<data ype>(<len>) e.g.:  char(3) ;

 

Data Element - S_CURRCODE;



ABAP Premitive types - abap.char(3);



To use the parameters to filter out the data we need to apply a ‘WHERE’ clause and use the parameter with $Paramter keyword i.e. $Parameter.<parameter name> OR just the parameter name prefixed with a colon i.e.  :<parameter name> .  Let’s check how the CDS view look like now;



OR



  • Active the CDS view now and hit F8 to execute. Checkout the user input pop up to enter the currency code as we configured in the CDS view;




 

  • Add ‘AUD’ for Australian Dollar and hit ‘OK’. Check the output ?




 

  • Now lets see how we can consume this CDS view with parameters in our ABAP program. What new code we need to write and how the parameters behave;


Create a new ABAP program ZCONSUME_CDS_PARAM and add code as below
*&---------------------------------------------------------------------*
*& Report zconsume_cds_param
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zconsume_cds_param.

data: lv_curr type S_CURRCODE.
cl_demo_input=>new( )->add_field( changing field = lv_curr )->request( ).

select * from ZCDS_VIEW_PARAM( in_curr = @lv_curr ) into table @data(lt_tab).

cl_demo_output=>display( lt_tab ).



 

The ‘Enter’ button here is automatic, we don’t need to write any code for this.  Enter the currency value and hit Enter;



 

To summarize, in live projects 95% of analytics needs selection screens to get user input.  This is also very important to reduce the amount of data hit by the CDS view which subsequently improves the CDS view performance to fetch only the required data out.  In this blog post, we saw how to use the parameters to get the user input and fetch only the data needed for analytics.

 

Part# 7. How to search for SAP standard CDS Views : Find ways to search for SAP delivered CDS content.

 

Follow for upcoming blog posts: kumarsanjeev

Keep learning..

SK
5 Comments
former_member682484
Discoverer
0 Kudos
Great document again Sir. Thank you so much.
thyagab
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Sanjeev,

Could you please explain how to extend a standard CDS view which has input parameters.

Need to change the parameter default value in the extend view.

Thanks

Thiyagarajan
kanishakgupta1
Contributor
0 Kudos
Hi Sanjeev,

 

Thanks, Can we also use select options as input to CDS views so that we can also utilize the select options and not the parameters?

 

regards

Kanishak
0 Kudos
How can we add search help/F4 help to the added parameters ?
0 Kudos

 

Hi Sanjeev,

How can we make this parameter as optional, by default it is mandatory.

I couldn't found exact solution for making parameter as optional.

I am using the cds view [ with parameters ] as a datasource in SAP BW system.

Thanks,

Vijay Reddy

 

 

Labels in this area