Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
Showing results for 
Search instead for 
Did you mean: 
CDS view with input parameters consumption via OData

I decided to write this blog after I spent a lot of time in figuring out how to consume the CDS view with input parameter via OData.Hope this helps

CDS view with input parameters require a special syntax when you are making a call via OData. The steps to be followed in the CDS View are:
1) Annotations: Odata.publish:true
2) If you have Date field as your input parameter with datatype as Dats ,it might create an issue so cast it to Char. You will get the following error in that case:
“In the context of the Data services an unknown internal server error occured”.
You might also get that error if you are projecting any fields with dats as the datatype and trying to consume in OData

I will now create a basic CDS view with input parameter.
@AbapCatalog.sqlViewName: 'ZICMCALDATECHNG'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'ZI_CM_CALENDAR_DATE'
@OData.publish: true
define view ZI_CM_CALENDAR_DATE with parameters
P_CutDate : char08,
P_cutofftype : zreport_type
as select from scal_tt_date
key cast (scal_tt_date.calendardate as abap.char( 08 )) as NewDate,
scal_tt_date.yearmonth as YearMonth,
scal_tt_date.yearquarter as YearQuarter,
scal_tt_date.yearweek as YearWeek

where scal_tt_date.calendardate = $parameters.P_CutDate

I am trying to get the calendar date,year month and week from the calendar table with input parameter as P_Cutdate with char08 as datatype.

Now you can proceed to gateway /n/IWFND/MAINT_SERVICE to activate your service.After activating your service the metadata should look like this:

Look closely in the metadata.
There are two entityset in the entitycontainer

Take the second entityset and prepare your url
The url will look like this:

Remember to put the Set at the end. You can also get Results in the 1st entity depending upon your service generation in the gateway. Then you have to type /Results after the url to get the data

The data will look like this:


Hope this helps
Labels in this area