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.
cancel
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
1) ZI_CM_CALENDAR_DATESet

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

/sap/opu/odata/sap/ZI_CM_CALENDAR_DATE_CDS/ZI_CM_CALENDAR_DATE(P_CutDate='20170217',P_cutofftype='EOD')/Set
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
18 Comments
Former Member
0 Kudos
Awesome.  Thanks.  It helps !!!
ajith_c
Explorer
0 Kudos
Thanks
dayakarp
Explorer
0 Kudos
Nice blog..

 

Thank you.
VladyslavShchur
Explorer
Thanks man, you made my day! 🙂
smarchesini
Active Contributor
0 Kudos

Thank you for blog ! ?

Ramprabhu_Sukum
Product and Topic Expert
Product and Topic Expert
0 Kudos
Thanks for sharing the knowledge
VijayCR
Active Contributor
0 Kudos
Hello prabuddha.singh ,

Thanks for sharing Very Informative But how to get the results alone with /Set I see the result along with the other details. .As per below :

I tried "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".

I tried with the /Results but it does not work getting an error message

"The request URI is not valid. Since the segment 'Set' refers to a collection, this must be the last segment in the request URI. All intermediate segments must refer to a single resource."

Is there any other way to get the results alone as I have to read this service in ABAP using Http classes.
0 Kudos
HI Vijaya,
Whatever is there in the entitycontainer, you should prepare your URL according to that. I dont understand your statement: "how to get the results alone with /Set". you will get the full entity when you use /Set or /Results: depends on your gateway settings which term to use. open the sap gateway client and see the entity sets generated in the metadata of the service.

regards,
Prabuddha Raj
jitendra_it
Active Contributor
0 Kudos
Hello prabuddha.singh

Could you please explain why we need to /Set in below url ? I tried without Set and it is giving error.

/sap/opu/odata/sap/ZI_CM_CALENDAR_DATE_CDS/ZI_CM_CALENDAR_DATE(P_CutDate=’20170217′,P_cutofftype=’EOD’)/Set
0 Kudos
Hi jitendra,
You need /Set as it is part of the entityset in the cds view. This /Set is determined through your gateway settings and how the service is generated out of the CDS view. So it is a standard way to call the genrated service out of a CDS view
Christer
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi,

I have this "..sap/opu/odata/sap/YY1_TEST_CDS/YY1_TEST(P_StartDate=2012-10-10T12:34:56,P_EndDate=2019-10-10T12:34:56)/Set" and the dates are of type Edm.DateTime. Is the date syntax correct? Is the overall syntax correct?

I get, when run with Postman: "Malformed URI literal syntax"

I have this:

<EntityType Name="YY1_TESTParameters" sap:semantics="parameters" sap:content-version="1">
<Key>
<PropertyRef Name="P_StartDate"/>
<PropertyRef Name="P_EndDate"/>
</Key>

....

And

<EntitySet Name="YY1_TEST" EntityType="YY1_TEST_CDS.YY1_TESTParameters"
Christer
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi,

I'm testing at sandbox two with "https://gdm-es-sandb-two-api.demo.hybris.com/sap/opu/odata/sap/YY1_CH_SIMPLE_TEST_CDS" but I don't know how to perform the below:

"Now you can proceed to gateway /n/IWFND/MAINT_SERVICE to activate your service.".

Where do I activate the service in my case?
former_member347024
Discoverer
0 Kudos
This article is such a gem! Thankyou so much!
former_member688137
Discoverer
0 Kudos
Hi Guys,

Thanks for the valuable information.I tried providing the parameters with /Set but getting the error in O Data feed.

The URL i provided is

/sap/opu/odata/sap/C_SALESANALYTICSQRY_1_CDS/C_SALESANALYTICSQRY_1(P_ExchangeRateType='M',P_DisplayCurrency='USD')/Set

Iam getting error 400 bad request.

Here the source is CDS View .Please correct the URL if its not correct.

 

Regards,

Pradeep
0 Kudos
try

(P_FromDate=datetime'2020-09-10T00:00:00',P_TODATE=datetime'2020-09-10T00:00:00')/Results
johnnymunoz
Explorer
0 Kudos
Hi prabuddha.singh

Nice blog, thx. I implemented the gateway and the service works, but one of the URI's doesn't work, What do I need to configure?

/sap/opu/odata/sap/ZCDS_BPDATA01_CDS/ZCDS_BPDATA01(rut='19722304-9')/Set - Works

/sap/opu/odata/sap/ZCDS_BPDATA01Set(rut='19722304-9',partner='1006673208') - Don't works.

Best regards,

Johnny
0 Kudos
Hi Johnny,
it depends on the metadata of the service. if the gateway is implemented with ZCDS_BPDATA01Set then you have to use /Set . in somecases the enitityset in the DPC classes is generated as ZCDS_BPDATA01Results, then you have to use /Results to get the data .
regards

Prabuddha Raj
KarthikCheers
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you very much. It was very helpful at the need of the hour. Appreciate your effort in documenting and sharing it with the community.