Quantcast
Channel: SAP Gateway
Viewing all articles
Browse latest Browse all 137

OData service development with SAP Gateway using CDS via Referenced Data Sources

$
0
0

Introduction

 

In a previous blog OData service development with SAP Gateway - code-based service development - Part I I described how to implement as basic OData Service using code based implementation.

 

Since the recommended development approach as of SAP NetWeaver 750 is to use CDS views I would like to show how a service having the same capabilities as the service in the blog mentioned above can be generated based on CDS views.

 

It will turn out that from a development perspective in the ABAP stack this is much less effort if appropriate CDS views are in place and if your backend system is based on SAP NetWeaver 750.

 

If however no appropriate CDS view is in place instead of having the effort of developing an OData service via code based implementation you would have the effort to develop the appropriate DDL source code.

 

 

Generating an OData service via Referenced Data Source

 

  • We first have to start with creating a new Service Builder project calledZE2E100_<XX>_2 since the project in the previous blog mentioned above was calledZE2E100_<XX>

    Note:
    Replace <xx> with your group number
  • Right click on the folder Data Model.

    Choose Reference -->
    Modeled Data Source Reference from the context menu

image082.png

  • The Reference Data Source Wizard opens.


    On the first screen choose:
    CDS Core Data Services for the field Modeled Data Source Type.
    SEPM_I_SALESORDER_E for the field Modeled Data Source Name

rds01.jpg

  • In the second window of the wizard select the following associations’

    _CUSTOMER and _ITEM.

    Please note that the cds views SEPM_I_BUSINESSPATNER_E and SEPM_I_SALESORDERITEM_E are automatically selected as well.


    Press Finish


rds02.jpg

Please note that the CDS views SEPM_I_SALESORDER_E and SEPM_I_SALESORDERITEM_E are both marked as "Analytical". This will have a result in the format of the key values of the results as being shown later in this blog.


  • Press the Generate Runtime Objects button


  • In the Model and Service Definition screen leave the default values unchanged and press Continue.

image086.png

  • In the Create Object Directory Entry dialogue press Local Object or enter $TMP.


  • Expand the folder Service Maintenance right click on the entry GW_HUB and choose Register.

image088.png

  • In the Add Service dialogue enter $TMP for the package assignment or press Local Object.

image089.png

  • Expand the folder Service Maintenance right click on the entry GW_HUB and choose SAP Gateway Client.

    Press <Execute>

image090.png

  • Check the Service Document

    It shall contain three entity sets:
    1. SEPM_I_SalesOrder_E
    2. SEPM_I_SalesOrderItem_E
    3. SEPM_I_BusinessPartner_E

rds04.jpg

  • Check the metadata document by selecting <Add URI option> and select $metadata

 

Check the Metadata Document
Please note that the entity type SEPM_I_SalesOrder_EType contains:

    • Two navigation properties to_Customer and to_Item
    • A property SalesOrder_Text that has been generated by the SADL framework based on the annotation @ObjectModel.text.association: '_Text'.

      Please note this property is annotated as sap:updatable=”false”;

 

rds06.jpg

  • Now we can test the service and we will see that it supports various query options, $expand and selecting single entities out of the box.

    To do so execute the following URI’s in the SAP Gateway Client (transaction /n/IWFND/GW_CLIENT):
    • /sap/opu/odata/SAP/ZE2E100_XX_2_SRV/SEPM_I_SalesOrder_E?$filter=GrossAmountInTransacCurrency ge 100000&$select=SalesOrder,GrossAmountInTransacCurrency,TransactionCurrency&$format=json

 

    • $skip and $top together with $inlinecount work out of the box as well

      /sap/opu/odata/SAP/ZE2E100_XX_2_SRV/SEPM_I_SalesOrder_E?$filter=GrossAmountInTransacCurrency ge 100000&$select=SalesOrder,GrossAmountInTransacCurrency,TransactionCurrency&$top=2&$skip=1&$inlinecount=allpages&$format=json

      Please note that via &$inlinecount=allpages we retrieve the number of entries that would be returned without using $skip and $top

rds09.jpg

    • Read a single entity from the list of the sales order

      /sap/opu/odata/SAP/ZE2E100_XX_2_SRV/SEPM_I_SalesOrder_E('-.-.-.-.-.-.10.-.-.-.-.-.-._.0500000000')?$format=json

      Please note that the weird looking key stems from the fact that the CDS view is annotated as an analytical view.

    • Read the list of items of a single sales order via the navigation property to_Item

      /sap/opu/odata/SAP/ZE2E100_XX_2_SRV/SEPM_I_SalesOrder_E('-.-.-.-.-.-.10.-.-.-.-.-.-._.0500000000')/to_Item?$format=json

 

 

How to implement updates in a service that has been generated using referenced data sources will be described in an upcoming blog ...


Viewing all articles
Browse latest Browse all 137

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>