Skip to Content

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

To report this post you need to login first.

19 Comments

You must be Logged on to comment or reply to a post.

  1. 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

    (0) 
  2. 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

    (0) 
    1. Vishnu Pankajakshan Panicker 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

      (0) 
    2. 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

      (0) 
  3. 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

    (0) 
    1. Vishnu Pankajakshan Panicker 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

      (0) 
      1. Divya Prasanth

        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

        (0) 
  4. 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

    (0) 
    1. Vishnu Pankajakshan Panicker 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

      (0) 
      1. 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

        (0) 
        1. Vishnu Pankajakshan Panicker 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

          (0) 
  5. 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

    (0) 
  6. 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

    (0) 

Leave a Reply