How to create OData service for ABAP CDS views using Referenced Data Source in SEGW

2
24896

Hello everyone, in this blog we will discuss on how to create OData service for ABAP CDS views in SEGW based on Referenced Data Source.

In previous blog How to create OData service for ABAP CDS Views we have seen an easy approach on exposing the ABAP CDS view as an OData service using the annotation @OData.publish: true and also the restrictions/disadvantages by following the approach.

Referenced Data Source

To overcome the above restriction, we can follow this approach. Below are the features supported.

Advantages and Features Supported

  • Multiple Entities i.e multiple CDS views
  • Associations
  • Actions using Function Imports in SEGW
  • CDS View with parameters
  • CDS annotations considered and derived at runtime
  • CDS changes will be reflected at runtime, no need for re-activation

Prerequisites

Basic understating of ABAP CDS views, to know more click here.

Step-by-Step Procedure

1. Creating an New Project

Launch SEGW – Gateway Service Builder transaction on front-end server(FES).

Create OData Service for ABAP CDS views using Referenced Data Source Approach

Click on Create Project and provide the necessary details on Create Project dialog box.

Create OData Service for ABAP CDS views using Referenced Data Source Approach: Create SEGW Project

A new SEGW project will be created with empty data model like below.

1.2. Reference Data Source

Create OData Service for ABAP CDS views using Referenced Data Source Approach: Select Reference Data Source

Now right-click on the Data Model choose Reference and then Data Source.

Create OData Service for ABAP CDS views using Referenced Data Source Approach: Select CDS View Entity

A new Reference Data Source wizard will open like below. Choose ABAP CDS view using the F4 help and hit Next.

Create OData Service for ABAP CDS views using Referenced Data Source Approach: Select CDS View Entity Fields

In the next wizard step check the information and hit Finish.

Create OData Service for ABAP CDS views using Referenced Data Source Approach: Exposure via SADL

ABAP CDS entity will be successfully referenced in the SEGW project and new folder Data Source References will be created under Data Model folder.

Create OData Service for ABAP CDS views using Referenced Data Source Approach: CDS Entity based Entity Sets

Entity types, Entity Sets and Associations will automatically created for the ABAP CDS view.

You can further explore the properties and other artifacts created.

2. Generating Model Provider Class/Data Provider Class and Other Runtime Objects

Navigate and select the project node and hit Generate Runtime Objects button to generate the SEGW OData service run-time artifacts.

Create OData Service for ABAP CDS views using Referenced Data Source Approach: MPC and DPC Classes

On Model and Service Definition dialog box, a list of classes is shown and will be generated. You can go with default name or change them if you like to give different names and hit OK

On the Create Object Directory Entry dialog box, enter a value (e.g. $TMP) to the Package field, and then choose Save.

Now the service classes are generated.

3. Activating Service

Launch the transaction /IWFND/MAINT_SERVICE – Activate and Maintain Services.

Create OData Service for ABAP CDS views using Referenced Data Source Approach: Activate OData Service

Choose Add Service.

On Add Selected Service screen provide the value for System Alias field and then choose Enter. A list of services is then displayed.

Create OData Service for ABAP CDS views using Referenced Data Source Approach: Register OData Service

From the list of services choose the relevant service, you can search based on your project name. Click on Add Selected Services

Create OData Service for ABAP CDS views using Referenced Data Source Approach: Activate OData Service SICF

On Add Service dialog box specify the package name and choose Enter.

Activate Service in SEGW 3

Service is successfully activated with message dialog box like below.

Test Service in Gateway Client 1

Go back to the Activate and Maintain Services screen and filter with service we just created above. Choose SAP Gateway Client.

4. Test Service in Gateway Client

Test Service in Gateway Client 2

On SAP Gateway Client, choose Execute to view the metadata of the OData service.

Test Service in Gateway Client 3

Navigate to EntitySets button from the application toolbar and choose the entity set.

Test Service in Gateway Client 4

Choose Execute to view the data retrieved from the ABAP CDS view.

Conclusion

Congrats..! You have successfully created an OData service for ABAP CDS view using SEGW based on SADL framework. Please stay tuned for ABAP CDS View Tutorials. Leave a comment in the below comment section and let us know your feedback.

Comments are closed.