NW ABAP Gateway (OData), SAP ABAP CDS

Creating OData Services with CDS using SADL and Annotation.

This blog tells about OData service creation using Core Data Services [SAP ABAP CDS for SAP S/4 HANA] at the same time here we going to explore two methods for creating OData service one is SADL and another one with CDS annotation.

Let’s start with an exact definition of OData: OData can be defined as a REST-based protocol for querying and updating data. It is built on technologies such as HTML or XML and JSON.

The two methods are:

  • @OData.publish: true[Annotation]
  • SADL Exposure
Fig_1: Block diagram represents two methods for creating OData services using CDS

Let’s begin with Annotation “@OData.publish: true

For creating an OData service for ABAP CDS using annotation let’s begin with creating CDS view here I have created two CDS views one is ZZZ_BP_BASIC on top of that I have created another view ZZZ_ASSO_BP and those are below.

Fig_2: CDS View: ZZZ_BP_BASIC
Fig_3: CDS View: ZZZ_ASSO_BP

Now let’s add an annotation “@OData.public: true” just above the define view statement.

Once you added the OData Annotation to your view you can see a little yellow warning icon just hover your cursor over the warning icon you can see the CDS view name along with _CDS which is nothing but the service name. Copy the service name.

  1. Open SAP GUI and enter Tcode /n/IWFND/MAINT_SERVICE to register the service.
  2. Choose Add Service
  3. Give the system Alias name as ‘Local’ and paste the service name copied before[ZZZ_ASSO_BP_CDS] in the external service name text box and then click enter.
  4. By selecting on created service name click add selected services.
  5. Assign a package.

Please make use of the following screenshots to register your service.

Yes! The server got registered successfully. Now we are ready to expose ERP Data or SAP S/4 HANA Data or SAP CDS View Data through OData Service.

Again move to the eclipse editor in the outline right click on OData Exposure and give your system username and password. It opens up our OData service [If you can’t find the outline in your editor Window > Show View > Outline].

We have successfully registered a service using annotation and now let’s move to SADL.

Creating OData Service using SADL.

SADL (Service Adaptation Description Language) is an ABAP technology that enables the consumption of entity relationship-like ABAP data models in various scenarios with a common development experience based on a model-driven approach.

Here I have created a CDS View ZZZ_BP_SADL on top of ZZZ_BP_BASIC. The best thing about using SADL is we can create a service with the names we entered manually.

  1. Open SAP GUI or press ctrl+6. Enter Tcode SEGW.
  2. Click on Create Project.
  3. Manually create a project with the name you preferred along with a description and click on Local object.
  4. Right-click on Data Model>Reference> Data Source.
  5. In the CDS Entity text bar enter the CDS view name on which you decided to create OData Service. In this case, it’s ZZZ_BP_SADL and click on next.
  6. Finally, click finish.
  7. Save and click on Generate Runtime Object.
  8. Copy the technical service name.

Please make use of the following screenshots to create a service using SEGW Tcode.

Now again go back and enter the Tcode /n/IWFND/MAINT_SERVICE to register the service. Follow the same steps as before[The steps we followed to create an OData service using annotation].

  1. Choose Add Service
  2. Give the system Alias name as ‘Local’ and enter the service name [project name along with _SRV] ZSALESORDER_SRV in the external service name text box and then click enter.
  3. By selecting on created service name click add selected services.
  4. Assign a package.
  5. Just go back once you successfully created the server choose filter and filter the service name you created.
  6. Then click the “Call Browser” and choose to allow.

Please make use of the following screenshots attached below.

Congratulations we have created an OData service with the name we entered manually using SADL.