SAP RAP Programming: Building Your First OData Service


🚀 Introduction

SAP RAP programming empowers developers to build scalable, cloud-ready applications using ABAP. At the heart of this model is the ability to create and expose OData services, which are essential for building SAP Fiori apps and integrating with external web clients.

In this blog, we’ll walk through the Getting Started guide for SAP RAP, using the ABAP Flight Reference Scenario. You’ll learn how to create a CDS view, expose it as an OData service, and understand the role of annotations in shaping the user interface.


✈️ What Is the ABAP Flight Reference Scenario?

The Flight Reference Scenario is a demo dataset provided by SAP that includes travel-related information such as flights, bookings, customers, and agencies. It’s used throughout SAP’s RAP development guides to demonstrate real-world application building.

This scenario assumes that the necessary database tables already exist, allowing you to focus on building the application logic and service layer.


🧱 SAP RAP Programming: Step-by-Step Guide

We will start by creating a data model and will then create Business Service and Bindings for consumption.

1. Create a CDS View Entity

We will create a CDS view entity for table /DMO/Connection but first have a look at this table and data. You can open any object in eclipse using CTRL+SHIFT+A and enter the name.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Take a look at the data of this table simply press F8.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

As this is your first object, if you need create a package or use an existing one.

To create our data model, right click on package and select new data definition.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Enter name and description and give Reference object which in our case is Connection table.

Click next, give TR or create TR if required.

We will create our Data model using CDS view entity. Select CDS view entity template on the next screen and click finish.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Now a CDS view entity for our Connection table will be created. Activate it and you can also give an alias name for tables or different data sources.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Tip: To format code, you can use Shift+F1 in eclispse.

Give it a run pressing F8 and you can see the same data as the table.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Now we will relate the semantically dependent elements but what are they?

What are Semantically Dependent Elements in SAP RAP Programming ?

In Core Data Services (CDS), semantic annotations are used to define standardized meanings for data elements, ensuring they are interpreted correctly by consuming applications. These annotations are especially important for elements that represent:

  • Monetary amounts – which require a reference to the associated currency.
  • Measured quantities – which need a reference to the relevant unit of measure.

By linking these elements to their respective units through annotations, CDS ensures that they are treated as interdependent in the resulting OData service. This is particularly beneficial for user interfaces, where values are automatically displayed with the correct formatting and decimal precision based on their unit or currency.

For our case we need to relate the distance field with its unit field. We will use annotation semantics.quantity.unitofmeasure and give column name of its unit to relate these.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

2. Define and Bind an OData Service for SAP RAP Programming

Next, create a service definition and service binding to expose the CDS view as an OData service.

Bind the service to the OData V2 or V4 protocol, and publish it locally so it can be consumed by SAP Fiori or other web clients.

Creating Service Definition

Right click on your data definition and click on New Service Definition.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Give name description and other details and press next and finish.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Here we need to expose the data definitions which we need. Currently it is just one.

Activate.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Create Service binding

Right click on service definition and select New Service Binding.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

In next popup, give name description and binding type.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Binding type is important and based on our requirement we need to select this. For Web applications we will select Odata V2 or V4 Web API. For our case we will use Odata V2-UI .Please note the warning on usage as well while selecting the binding type. Apart from some scenarios for UI we go with Odata V4 binding type. The name of our service as per naming conventions are also impacted as per our selection. You can have a look on Naming conventions here.

Once done your Service will be created but you will need to activate it.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Once activate, publish the service.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

You can see the entity sets exposed here. If we have more than one entity sets we can see them here.

For a preview, click on the Preview button.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

The application will open on browser but it appears blank because we have not yet defined the Default columns and selection fields which we will do later.

Click on Settings button and select columns for display.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Click Go button to pull all data without selection for now.

SAP RAP programming, OData service, ABAP RESTful Application Programming Model, SAP Fiori Elements, CDS view, ABAP Flight Reference Scenario

Here we have a Simple List Report using RAP which we will of course refine in our next blog.


📱 SAP RAP Programming : Consuming the OData Service

Once published, the OData service can be consumed by:

  • SAP Fiori Elements apps
  • External web clients
  • Integration platforms

This enables seamless data access and interaction across various front-end technologies.


🧠 What We Have Learnt

By following this guide, you’ll be able to:

  • Create a CDS view from existing tables
  • Define and expose an OData service
  • Bind the service to a protocol and publish it
  • Use semantic and UI annotations effectively

📌 Conclusion

SAP RAP programming simplifies the development of RESTful applications by combining CDS views, OData services, and annotations into a unified framework. The Flight Reference Scenario is the perfect starting point for mastering these concepts and building your first SAP Fiori app.

Ready to take the next step?

Leave a Comment

Your email address will not be published. Required fields are marked *