Skip to Content
Author's profile photo Vishnu Pankajakshan Panicker

OData for CDS with Parameters

Hi Experts,

Let me share my experience and ‘How to’ while creating OData Service for CDS View with Parameters.

Disclaimer:

I am not sure whether the steps i will be explaining is the right one but i would like to share how i did it.

Step 1:

Add the Package to Eclipse Project Explorer and create a DDL Source .

doc1.PNG

Step 2:

Define a sample view with Parameter and Activate it.

cdsqry1.PNG

Anotation OData.publish will expose the CDS View as OData Service.

Step 3:

Add the Service using the /iwfnd/miant_service.

Step 4:

Get the metadata and find out the entitySet of an entity without a sap:parameter

doc3.PNG

Step 5:

Execute the URL as shown below

doc4.PNG

voila thats the result…

Open to comments and anybody can edit appropriately.

Happy Coding

Vishnu

Assigned tags

      32 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sudhanva Laxminarayan
      Sudhanva Laxminarayan

      Hello Vishnu,

      I have followed the steps as mentioned in the blog, but i am getting error while executing the URI as 'Resource not found for segment'.

      Could you please suggest!

      Thanks in advance.

      Regards,

      Sudhanva

      Author's profile photo Vishnu Pankajakshan
      Vishnu Pankajakshan
      Blog Post Author

      Hi Sudhanva Laxminarayan

      Provide me the request URI and the Respoionse in gateway client or from chrome browser.With that i can help u out.

      Regards,

      Vishnu

      Author's profile photo Rajiv Kumar
      Rajiv Kumar

      Hi Vishnu,

      If I want to get multiple values from the service, how can I pass the parameters. In your example, only one row is retrieved. Use case: Suppose I want to retrieve all employees of a department, so I give Dept_Id as parameter, and key will be obviously employee id only. So I don't want to give empid as input parameter in service, but only the dept id. Is it possible?

      Rajiv

      Author's profile photo Vishnu Pankajakshan
      Vishnu Pankajakshan
      Blog Post Author

      Hi Rajiv,

      Inside the CDS Definition you can custom code required queries.You can even have a Definition without parameters and in this sample Parameter is used in where clause for READ operation.

      Regards,

      Vishnu

      Author's profile photo Vishnu Pankajakshan
      Vishnu Pankajakshan
      Blog Post Author

      scn1.PNG

      scn2.PNG

      After Executing this in Client you can query all the results.Hope this helps.

      Regards,

      Vishnu

      Author's profile photo Gopalakrishnan Ramachandran
      Gopalakrishnan Ramachandran

      Hi Vishnu,

      Thanks for the blog. It was good and informative.

      Hi Rajiv,

      If you want to use Dept_Id as parameter and empid is your key, then you can use something as follows:
      /sap/opu/odata/sap/ZEMPLOYEE_SAM_PAR_CDS/Zemployee_Sam_Par(Dept_Id='010')/Set

      If you check the screen shot of $metadata in the blog by Vishnu, one entity type with name Zemployee_Sam_ParParameters is created and corresponding entity set is Zemployee_Sam_Par (which is equivalent to name of CDS).
      Also, a, association from Parameter Set to CDS View Set (Zemployee_Sam_ParSet) is created having Navigation Property Name as "Set".

      Best Regards,
      Gopal

      Author's profile photo Rama Sudhakar
      Rama Sudhakar

      Hi Vishnu,

      Which version of SAP is required to run this, we are currently using Release 740 and Service pack level 0004. when go to the SICF T-code navigate to the path my service is not there, Please suggest what should we required.

      Regards

      Sudhakar

      Author's profile photo Vishnu Pankajakshan
      Vishnu Pankajakshan
      Blog Post Author

      According to Documentation NW 740 would suffice i suppose.

      After creating your CDS and exposing it as OData you must go to T-Code /iwfnd/maint_services to add the Service.Then it would appear in the ICF.

      Regards,

      Vishnu

      Author's profile photo Former Member
      Former Member

      Hi Vishnu,

      I am trying to create an Odata services based on a CDS view with parameters on NW 740 with SPS 12. I have created the service via SEGW. But the problem is I cant access the same via the URL.

      My CDS view has an input parameter p_dist which is not part of the SQL view and hence the URL keeps throwing an error.

      Could you please if possible share screen shots of the service that was generated in the system , so I could look at how you have mapped the entities.

      Thanks

      Divya

      Author's profile photo Vishnu Pankajakshan
      Vishnu Pankajakshan
      Blog Post Author

      Give me the metadata information.

      Author's profile photo Raina Goyal
      Raina Goyal

      Hi Vishnu Pankajakshan,

      I have created a CDS view with input parameter and also created service via SEGW. I am following two approaches :

      1. While I am testing the service in gateway client, it returns me 200 and when i execute the uri for metadata , it is working fine. But when i follow step 5 of your blog ie. when i test the service with my parameter value as depicted in your step 5, it throws me error 500. I have tried every possible way and unable to understand where am i going wrong. Should i need to code or redefine any method or what. Please guide me.

      2. When I use  annotation @odata.publish:true in the CDS view it throws me warnings for the cds view as view does not exist and odata exposure is not possible which is restricting CDS view to activate also when I am checking in /iwfnd/maint_service , I am unable to find my service to add it. Or it can be said that I am confused how to find the automatically created service by using this annotation.

      So please guide me and help me  to solve this problem as I am struggling a lot in this and have an urgent requirement for this. Your guidance would be helpful.

      Thanks,

      Best Regards,

      Raina

      Author's profile photo Vishnu Pankajakshan
      Vishnu Pankajakshan
      Blog Post Author

      Hi Raina Goyal,

      Sorry for the delay..can u provide the metadata information of ur service.... Give me a screenshot for the GW_CLIENT Exection.

      Kindly letme know the system info.

      Regards,

      Vishnu

      Author's profile photo Raina Goyal
      Raina Goyal

      Hi Vishnu Pankajakshan

      Please find the below screenshot for the metadata information of my service:

      Metadata.png

      /wp-content/uploads/2016/09/metadata2_1040165.png

      System is ECC 7.4

      Thanks,

      Best Regards,

      Raina

      Author's profile photo Vishnu Pankajakshan
      Vishnu Pankajakshan
      Blog Post Author

      Your metadata seems fine.. i think since you system is ECC and 7.4 NW you need to try the traditional method of  service creation using SEGW where u can create one using CDS Views.I have seen documents explaining those.I came to this conclusion becoz it throws for you while using OData.publish . This was introduced in NW 7.5 System i suppose.

      Regards,

      Vishnu

      Author's profile photo Raina Goyal
      Raina Goyal

      Hi Vishnu,

      As I have mentioned earlier in my first comment , I have created my service using SEGW also, the service is working fine with metadata but while I test it with particular input parameter of the CDS view as you are doing in step 5 of your blog i.e URL/zemployee_SAM_PARSET(p_empid=2,empid=2). For my case URL/SANKYSet(yfvglobcc=50290), it is giving me 500 error. So I need to know where am I going wrong.. Should i need to code or redefine any method or what?Could you please help me and guide me.

      Thanks,

      Best Regards,

      Raina

      Author's profile photo Vishnu Pankajakshan
      Vishnu Pankajakshan
      Blog Post Author

      Even though i haven't personally tried exposing CDS View to OData via SEGW let me try.For that can you try giving me the error_log details??? and since its a READ Opeation can u try debugging the GET_ENTITY Method and lemme know what u get there.. 🙂

      Regards,

      Vishnu

      Author's profile photo Vishnu Pankajakshan Panicker
      Vishnu Pankajakshan Panicker
      Blog Post Author

      @raina_goyal have u tried debuggging the DPC Classes and checked for any exception.????

      Author's profile photo Vishnu Pankajakshan Panicker
      Vishnu Pankajakshan Panicker
      Blog Post Author

      @raina.goyal

      Your datatype is Edm.String in Metadata but you are passing value as like in an integer. URL/SANKYSet(yfvglobcc='50290')

      Sorry for replying very late.

       

      Thanks ,

      Vishnu P

      Author's profile photo Dikshith S
      Dikshith S

      Hi Vishnu,

      How will you pass the non-key attribute as a parameter in odata URL?

      it will be helpful if you share the information.

       

      Thanks & Regards,

      Dikshith

      Author's profile photo Hari Krishna Reddy P
      Hari Krishna Reddy P

      Hi Vishnu,

      I have followed the same steps for creating the OData from the CDS view by using the OData.pulish:true.

      Last week it was working fine, suddenly the metadata of the service got changed. Now the metadata data is loading without the parameters Entity Type and without the Entity Set of an Entity Type without sap:parameter. The same service is giving correct metadata in some other systems(performance system). I have mentioned the metadata links with screenshots below.

      Links:

      ER9/001 (metadata is wrong ) – https://ldai3er9.wdf.sap.corp:44300/sap/opu/odata/sap/C_TEAMUTILIZATIONRATE_CDS/$metadata

      CCW/715(loading correct metadata) –    https://ccw-715.wdf.sap.corp/sap/opu/odata/sap/C_TEAMUTILIZATIONRATE_CDS/$metadata

       

      Do you have any idea why the metadata is loading without parameters?

      Thanks & Regards,

      Hari

      Author's profile photo Vishnu Pankajakshan Panicker
      Vishnu Pankajakshan Panicker
      Blog Post Author

      Hey Hari,

       

      Could you give me the details of the NW Version of ER9 and CCW?

       

      Thanks,

      Vishnu P

      Author's profile photo Ioannis Mathioudakis
      Ioannis Mathioudakis

      Hi following your ‘How to’ I have managed to create a CDS View and expose oData. I’m able to retrieve the metadata of my service but I cannot execute service from browser request passing parameters.

      Bellow is the metadata for the CDS View service

      Basically what I want to do is to pass date_from and date_to properties and get the response. The other fields that are members of the key cannot really specify a single entry (and also not really define a key) so I don’t want to have the information to pass it into the request URI.

      So I’m trying to call the service with request URI:

      :8000/sap/opu/odata/sap/ZCDS_EMPLOYEE_SALES_CDS/ZCDS_EMPLOYEE_SALESSet(date_from=20180913,date_to=20180913)

      or

      :8000/sap/opu/odata/sap/ZCDS_EMPLOYEE_SALES_CDS/ZCDS_EMPLOYEE_SALESSet(date_from=’20180913′,date_to=’20180913′)

      Both returns me the same error

      And the error message for both from /IWFND/ERROR_LOG is

       

      This is the definition of my parameters in the CDS View

       

      dats is a data element of type abap.dats Already defined in the system.

      Edit: Also the request URI 

      :8000/sap/opu/odata/sap/ZCDS_EMPLOYEE_SALES_CDS/ZCDS_EMPLOYEE_SALES(date_from=20180913,date_to=20180914)/Set

      Results in the following error:

      So, basically I just need to format the date URI properly but I don’t know how. Anyone who could provide me with information or a document on URI format for each type would be welcome! 

       

      Edit2: As mentioned by Gopalakrishnan Ramachandra the correct way to pass parameters to pass the parameters into the URI, also I was needed to determine the type of argument and fix the format of the datetime so the working URI for my case was

      :8000/sap/opu/odata/sap/ZCDS_EMPLOYEE_SALES_CDS/ZCDS_EMPLOYEE_SALES(date_from=datetime'2018-09-13T00:00:00',date_to=datetime'2018-09-14T00:00:00')/Set?$format=json

      Author's profile photo Vishnu Pankajakshan Panicker
      Vishnu Pankajakshan Panicker
      Blog Post Author

      Type is 'date time ' and you should pass using exact format.

       

      Refer below url.

      https://blogs.sap.com/2017/01/05/date-and-time-in-sap-gateway-foundation/

       

      Author's profile photo Jay Malla
      Jay Malla

      This was really helpful.  It's very strange how you have to make the OData with the parameter in the URL with /Set.  I would not have guessed this.  Your comment saved a lot of time.

       

      Thanks,

      Jay

      Author's profile photo Vishnu Pankajakshan Panicker
      Vishnu Pankajakshan Panicker
      Blog Post Author

      Hi All,

       

       

      Kindly follow the below link that would help us to learn how to consume CDS in OData(Reference Datasorce).

      https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.5.9/en-US/32bc41261af445e08182c8532032f950.html

      Thanks and Regards,

      Vishnu P

       

       

      Author's profile photo Kameswararao Gonugunta
      Kameswararao Gonugunta

      Hello Vishnu

      I am NW 7.4 and I am not seeing parameters in metadata . Is it only applicable on 7.5

      Author's profile photo Vishnu Pankajakshan Panicker
      Vishnu Pankajakshan Panicker
      Blog Post Author

      Hey,

      Yeh NW version does make difference. Try the same in 7.5.

       

      Author's profile photo Shani Niza
      Shani Niza

      Hi Vishu,

      I am getting below error while I am using annotation odata.publish : true

      Model 'ZBRI_VENDOR_CDS' version '0001' not found
      - Service ZBRI_VENDOR_CDS does not exist
      - Class ZCL_ZBRI_VENDOR does not exist
      - Service ZBRI_VENDOR_CDS is not active
      - Default Authorization Values are missing for Service ZBRI_VENDOR_CDS 0001
      - View has generated Objects
      - Entity CDS-ZBRI_VENDOR: Parameter vendor_name has no data element

      Author's profile photo Vishnu Pankajakshan Panicker
      Vishnu Pankajakshan Panicker
      Blog Post Author

      Hey Nisha,

       

      Try consuming the CDS as Reference source rather than exposing via annotation.

      There we have lot of flexibility to extend and tailor the service depending on different scenarios.

      And try the below document.

      https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.5.9/en-US/32bc41261af445e08182c8532032f950.html

      Regards,

      Vishnu P

       

       

      Author's profile photo Jaime Rodríguez Capote
      Jaime Rodríguez Capote

      Hi, could you fix this error?

       

      I'm having the same issue

      Author's profile photo Sachin Shinde
      Sachin Shinde

      Hi Jaime ,

      For the errors mentioned by Shani , check with your basis guy, as this might be authorization issue while exposing cds to Odata via annotation. Take screenshot of su53 from gui once you get this error in adt/hana studio and send it to basis guy.

       

      Hope this will work.

       

      Regards,

      Sachin

      Author's profile photo Christiano Hage
      Christiano Hage

      Very nice blog Vishnu!

      I'm struggling to run this oData service from S/4HANA Cloud:

      https://my300436-api.s4hana.ondemand.com/sap/opu/odata/sap/YY1_LIQUIDITYPOSITION_CDS/$metadata

      It has 3 parameters, but I cannot find a way to make it work. Could you share any insights?

      Regards, Chris