4

Creating OData API based on a Mapped Data Source

 3 years ago
source link: https://blogs.sap.com/2021/04/07/creating-odata-api-based-on-a-mapped-data-source/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

This blog post will provide the steps to implement the pagination in OData by leveraging the CDS view and the SADL framework based on Mapped Data Source.

Introduction:

SADL offers a mapping editor in the SAP Gateway Service Builder to bind one or several SADL models to OData entity sets. This enables you to use SADL models as an additional data source besides RFC and others. Once the OData properties are mapped, the system provides a standard, optimized implementation of the OData service to retrieve the data.

Please refer the below link for the prerequisites and supported SAP version.

https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.52.4/en-US/820b24ce35c745bb9e0fb3a6e8d6dbd4.html

Now let see how to create the Gateway project using CDS view and SADL framework.

Agenda:

Creating CDS view

Create Gateway project

Test from Gateway client

1. Create the CDS view:

Create the CDS view from Eclipse

  • Right click on the package icon, and from the context menu select New->other ABAP repository object.

        pic1-1.jpg

  • Enter the CDS view name and description as below:
  • pic2.jpg
  • Create the CDS view as below by selecting required fields from ACDOCA table.
  • pic4.jpg

2. Create Gateway project:

  • Now create the Gateway project from SEGW as below.
  • pic5.jpg
  • Once Gateway project is created, Right click on the Data Model and select ‘Import’ and DDIC Structure.
  • Enter the Entity Type Name and ABAP Structure and click on ‘Next’.
  • pic6.jpg
  • In the next screen, select the required parameters and click on ‘Next’
  • pic7-1.jpg
  • In the next pop up window, select the required key fields and click on ‘Finish’
  • pic8.jpg
  • As shown below, created the Gateway project with the entity type.
  • pic9-1.jpg
  • Next, in the service implementation, right click on the entity set and select the ‘Map to data source’.
  • pic10-1.jpg
  • Select F4 help on the Name field and enter the SADL model type as CDS Core Data Services and SADL model name as ZCDSV_ACDOCA_TEST. Select Enter.
  • pic11-2.jpg
  • The below screen will appear with the CDS view name. Select Enter.
  • pic12-1.jpg
  • Now map the SADL model elements to properties as shown below.
  • pic13-1.jpg
  • Once the mapping is completed, Press the Generate Runtime Objects button.
  • Note: Using the Generate Runtime Objects button automatically saves the project.
  • pic14-2.jpg
  • Like below, the Runtime artifacts will be generated.
  • pic15-1.jpg
  • Expand the node Service Maintenance and right-click on GW_HUB and select Register
  • pic16-1.jpg
  • In the Add Service popup leave all values as defaulted and press the Local Object button to                assign the artifacts to the $tmp package. Then press Enter to continue.
  • pic17.jpg
  • Double-click on the GW_HUB entry under Service Maintenance. Verify that the registration               status on the right-hand side is showing a green traffic light.
  • pic18.jpg

3. Test from Gateway client:

  • Now select the ‘SAP Gateway client’ and execute the service with the $skip and $top parameters to implement the pagination.
  • pic19.jpg

Conclusion:

Creating OData service based on mapped data source using the CDS view with SADL framework, enable to optimized implementation of the OData service to retrieve the data along with pagination.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK