How to create OData service in SAP NetWeaver Gateway

 

Introduction

In our previous blog, we looked into the introduction to OData and SAP NetWeaver Gateway. In this blog we will go through step by step process to create a SAP OData service. Later on, we will register our service and also test if it is working fine.

Step by Step Process to create SAP OData service

In this section we will follow multiple predefined steps to create an OData, these are:

  1. We will use SAP Service Gateway Builder (SEGW) to create a new project
  2. We will Import DDIC/CDS or other Structure to create an OData Model
  3. We will Generate our OData
  4. We will Register and test our Service

Create a new Service Builder project

To create a new project, follow the given steps:

  1. Go to transaction code SEGW, it will start the Gateway Service Builder.
  2. Click on the Create Project button, as shown below:
  3. Enter the given information

Field

Description

Example

Project

It is the name of your SAP OData Service. It will start with Z or Y

ZPROJECT_NAME

Description

Enter a description for your OData

Demo OData Project

Project Type

SAP Provides given four Project Options:

1.       Service with SAP Annotations

2.       Service with Vocabulary-Based Annotations

3.       Annotation Model for Referenced Service

4.       OData 4.0 Service

We will learn about them in details, later.

Service with SAP Annotations

 

Generation Strategy

It will be preloaded as Standard which means, it has all standard configurations.

Standard

Package

Enter your project package or temporary package i.e. $TMP

$TMP

Person Responsible

It will be preloaded with your User ID/ User Name

barryAllen

 




  1. Press Continue and Save.

Import a DDIC structure

To use an OData Service, it should be designed in such way that it will read/update one or more table. Therefore, we need to import any table, structure or view. These are part of DDIC structure. We can also import Data model from file, RFC/ BOR Interface or a search help. But in this section, we will learn how to import a DDIC structure:

  1. Click on the Data Model under the project we have recently created to expand it.
  2. Right Click on Data Model and click Import and then click DDIC Structure


  3. Now, a Wizard will open. Enter the following details, there:

Field

Description

Example

Name

Enter a name of Model. It should be explanatory.

CustomerData

Type

We have two options here:

1.       Entity Type: This means a simple DDIC structure/table/view will be imported

2.       Complex Type: This means a complex DDIC structure/table/view will be imported

Choose Entity Type

ABAP Structure

Choose your required table or structure name. Just copy and paste the name of your DDIC table/structure/view

zcustomer_data

Create Default Entity Set

It will create an Entity Type with the same fields as of Entity. Also, the name will remain same. We recommend you to leave it check marked.

Leave it check marked

 

The above details are shown below:



  1. In the next step, the wizard will show all the fields of the imported table. Just select them all and click next as shown below:


  2. In the next step, the wizard will show all the checked fields. Here you need to check the primary keys and finish, as shown below:

Generate OData Service

Now, we have created an OData object with a model. Now to use this Object we need to generate all the required classes. To generate, press the Generate Runtime Objects  OData Generate Icon button, as shown below:



Note: The Generate Runtime Objects button automatically saves the project before generating classes.

Pressing the above button, will open a dialog box as shown below:



Just press Continue, as shown above. The above process will generate following classes:

Class Name

Description

MPC Class

MPC stands for Model Provider Class. This is generated and refreshed every time, we generate a class. It is not recommended to extend this class for Model Annotations, because all the methods are deleted whenever the OData is generated.

MPC EXT Class

This is the Extended MPC class, and all the methods are conserved even the OData is generated.

DPC Class

DPC stands for Data Provider Class. This is generated and refreshed every time, we generate a class. It is not recommended to extend this class for CRUD operation, because all the methods are deleted whenever the OData is generated.

DPC EXT Class

This is the Extended DPC class, and all the methods are conserved even the OData is generated.

MDL Class

The is the Model Class.

SRV Class

This is the Service Class.

 

Just click on Lock Object to generate the classes, as shown below:


Register SAP OData using the Gateway client

Once the OData is generated, now it is the time to register the service. Once the service is registered, then only it can be used anywhere.

To generate an OData, follow the given steps:

  1. Double click the node Service Maintenance
  2. Select any System and click Register as shown below:


  3. Enter an Alias, if asked as shown below:


  4. Now, in the next screen you get following options:

Field

Description

Technical Service Name

This is auto generated service name

Service Version

It is auto generated service version

Description

It is the Description of the OData you have mention earlier

External Service Name

It is same to the auto generated service name

Namespace

It is by default bank

External Mapping ID

It is by default Empty

External Data Source Type

It is by Default set to source type C

Technical Model Name

It is auto generated Model Name

Model Version

It is auto generated Model Version

Package Assignment

Assign your package name here, or just choose Local Object from the button below. It will be then $TMP

ICF Node

It is by default “Standard Mode”

oAuth Enablement

It provides option to add extra authentication, in case you need oAuth2 enablement choose it, else leave it blank

 

In our case, we just need to choose package and click confirm, as shown below:

Once the service is registered, the Registration will turn green, as shown below:

Uploading: 28069 of 28069 bytes uploaded.


Test the OData service

  1. To test the OData service, click the SAP Gateway Client button, as shown below:

  2. It will open a new screen, here click Add URI Option as shown below:


  3. Choose $metadata, here:


  4. Click Execute as shown below:


If the status is 200, as shown above, then it means your OData is working fine.

In the next blog, we will look into how to do CRUD operations in OData

 

Previous
Next Post »