How to create OData Service for ABAP CDS View using Mapping Editor in SEGW


Hello everyone, in this blog post we will learn how to create an OData Service for ABAP CDS Views using Mapping Editor in SEGW(Gateway Builder).

There are 3 different ways to implement an OData service for an ABAP CDS view. Till now we have learnt 2 different approaches, in this blog we will learn the last approach using Mapping Editor in SEGW Gateway Builder. Please find the links below for the first 2 approaches.

Lets start the process by creating an ABAP CDS view in Eclipse ADT(ABAP Development Tools). Copy and paste the below DDL source code in the CDS view editor.

@AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'OData service on ABAP CDS View'

@OData.publish: true
define view ZODATA_DEMO as select from scarr 
key carrid      as AirlineCode,
    carrname    as AirlineName,
    currcode    as Currency,
    url         as AirlineURL

Save and activate the CDS view.

Step-by-Step Procedure

1. Creating a New Project

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

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

Create New Project in SEGW1.3  A new SEGW project will be created with empty data model like below.

Create New Project in SEGW 1

1.4  Right click on the Entity Types node which is under Data Model to create a new entity type.

OData ABAP CDS View Mapping Editor 0

1.5  On Create Entity Type dialog box, provide the Entity Type Name, tick Create Relate Entity Set check box to system proposed Entity Set Name. Hit OK button.
Note: To create an entity type you can directly import the DDIC Structure by right clicking on Data Model node → Import → DDIC Structure.

OData ABAP CDS View Mapping Editor 1

1.6  After creating entity type and its corresponding entity set, now the project will look like this.OData ABAP CDS View Mapping Editor 42. Mapping Editor

In this step we will map the ABAP CDS view data source to the entity set to retrieve the data

2.1  Expand Service Implementation node → Select and Right click on the entity set name to which you need to map the data source and choose Map to Data Source from the context menu.

OData ABAP CDS View Mapping Editor

2.2  On Map to Data Source dialog box, for Type field choose “Business Entity” and select value-help for Name field.

2.3  On Select Business Entity dialog box, chose the ABAP CDS view name and hit OK button.

OData ABAP CDS View Mapping Editor 2

2.4  On Mapping Editor screen, hit the button Generate Mapping to automatically map the fields. Instead you can also map the individual fields by drag and drop the fields.

OData ABAP CDS View Mapping Editor 3

3. Generating Model Provider Class/Data Provider Class and Other Run-time Objects

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

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

Generate Runtime Objects in SEGW

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

3.4  Now the gateway service classes are generated successfully.

4. Activating Service

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

4.2  Choose Add Service.Activate Service in SEGW

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

4.4  From the list of services choose the relevant service, you can search based on your project name. Click on Add Selected ServicesActivate Service in SEGW 1

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

Activate Service in SEGW 2

4.6  Service is successfully activated with message dialog box like below.Activate Service in SEGW 3

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

5. Test Service in Gateway Client

5.1  On SAP Gateway Client, choose Execute to view the metadata of the OData service.Test Service in Gateway Client 2

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

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

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.


Please feel free to comment and let us know your feedback. Subscribe for more updates.

If you liked it, please share it! Thanks!