Understanding the ABAP RESTful Application Programming Model

Objectives

After completing this lesson, you will be able to:
  • Describe the key components and capabilities of the ABAP RESTful Application Programming Model and its role in modern ABAP application development.
  • Use ABAP development tools.
  • Explain the ABAP RESTful Application Programming Model architecture.

ABAP RESTful Programming Model Overview

Modern ABAP Application Development

Four pillars summarize benefits of ABAP RESTful Application Programming Model, highlighting user experience, HANA integration, efficient development practices, and cloud extensibility for scalable, high-quality, and device-independent app development.

The ABAP RESTful Application Programming Model, also known as the ABAP RESTful Programming Model (ABAP RAP or RAP), provides a programming framework designed:

  • As a long-term strategic solution for modern ABAP development
  • To enable efficient development for SAP Fiori apps and Web APIs, whether creating applications from scratch or by integrating legacy code
  • To support an end-to-end development experience by providing:
    • Standardized development flow
    • Best practices and development guides
    • High development efficiency
    • Focus on business logic, rather than technical aspects
    • Native testability, documentability, and supportability
    • Code pushdown to SAP HANA
    • Convenient support for stateless and stateful environments
  • To support the product qualities:
    • User Experience: SAP Fiori and SAP HANA
    • Cloud: Scalability
    • Flexibility: Break-outs for non-standardized implementations
    • Out-of-the-box extensibility and verticalization

ABAP RESTful Application Programming Model

The ABAP RAP is a programming model for ABAP that is RESTful, which means that it meets the requirements of a REST architecture. In ABAP RAP, AS ABAP plays the role of a stateless Web server.

Overview of the ABAP RESTful Application Programming Model components, showing concepts, tools, frameworks, languages, and best practices supporting the efficient development of enterprise-grade applications.

What and Where to Develop with RAP

RAP primarily provides the following development options:

  • Service Development
  • Universal Programming Model
  • On-premise and in the Cloud
Diagram illustrates how RAP enables service development, a universal programming model for various project types, and deployment on both on-premise and cloud SAP systems.

Overview of RAP

Architecture stack shows SAP Fiori UI and other clients accessing enterprise application infrastructure and core data services via OData.

ABAP RAP comprises the following core building blocks:

ABAP Core Data Services (CDS)

CDS serves as the ubiquitous modeling language to declare domain data models.

Enterprise Application Infrastructure
The Enterprise Application Infrastructure offers:
  • Powerful service runtime frameworks
  • First-class support for SAP Fiori and SAP HANA
  • Out-of-the-box implementations
  • Draft support for SAP Fiori UIs
  • Built-in extensibility capabilities
OData

A standardized protocol for defining and consuming data.

Service Consumption

RAP supports user interface (UI) development, either based on SAP Fiori elements or as freestyle SAPUI5 development. It also supports service consumption via Web APIs.

Evolution Towards RAP

The ABAP RAP model represents the latest evolution of ABAP programming:

  • It maintains backward compatibility with earlier ABAP models, protecting previous investments in ABAP codebase and infrastructure.
  • RAP introduces cutting-edge features essential for building RESTful enterprise-grade applications optimized for modern cloud and hybrid environments.
Visual timeline compares the evolution of ABAP programming models and platforms, emphasizing ongoing investment security and the shift toward RESTful application programming.

ABAP Development Tools

ABAP Development Tools

ABAP Development Tools (ADT) is the successor of the ABAP Workbench. ADT provides the following features:

  • A completely new ABAP development experience on top of the Eclipse platform
  • An open platform for developing new ABAP-related tools
  • A set of open, language-independent, and platform-independent APIs that developers can use to build new custom tools for the ABAP environment
Show how to create an ABAP Project in ABAP Development Tools

An ABAP project serves as a container for the development objects that are stored in a particular ABAP back-end system and contains the logon parameters for the system logon: system, client, user, and language. You must be logged on to the system to edit an object. Within the ABAP project, you can access any development object in the repository. In addition, to make it easier to manage objects, you can set up favorite packages for each project.

Displays how to create new repository objects

To create a new repository object in ADT, right-click the project in the project explorer and choose NewABAP Repository Object.... In the following dialog box, you can search for the type of repository object you want to create.

Note

For some popular repository objects, there are direct menu entries under the New menu.
Displays how to Copy a Repository Object

To create a copy of an existing repository object, right-click the source object in the Project Explorer and choose Duplicate....

Note

You must specify the new package at the beginning of the dialog. In the classical ABAP Workbench, you specify the package at the end.
Shows how to Edit a Repository Object

To open a specific repository object in its respective editor, double-click it. The editor is shown on the right side of the ABAP perspective.

ABAP RESTful Application Programming Model Architecture

Architectural Overview of the ABAP RESTful Application Programming Model

Applications that are developed with the ABAP RESTful Application Programming Model consist of the following building-blocks:

Business Objects

Business objects (BOs) represent the data model and define the data-related logic, called behavior, independent of specific consumption. RAP business objects are defined through CDS data modeling views, CDS behavior definitions, and behavior implementations in ABAP classes.

Business Object Interface

A BO interface provides stable access to the functionality of a business object. If developers want to make a business object available for reuse in other development projects, they define and release a BO Interface. In RAP, a BO Interface consists of CDS projection views and a CDS Behavior interface.

Note

Interface-specific behavior implementations are not supported.
Business Object Projections

The BO projection is an approach to project and alias a subset of the business object for a specific business service. The projection enables flexible service consumption and role-based service designs. In RAP, a BO projection consists of CDS projection views, a CDS behavior projection, and, if needed, additional or consumption-specific behavior implementations.

Note

If the BO projection reuses an existing BO from another development project, it is built on top of the stable BO interface. If the business object and the BO projection belong to the same development project, the BO projection can access the business object directly. In this case, a BO interface is not needed.
Service Definition

A service definition defines the scope of a business service, in particular, the BO projection to be exposed via this service.

Service Binding

A service binding defines the communication protocol such as OData V2 or OData V4 and the kind of service to be offered for a consumer, such as UI services or Web APIs. Typical consumers for UI services are SAP Fiori UIs. Web APIs can be accessed by any other clients.

Business Events
A RAP business event usually represents a piece of information about the outcome of a modifying operation, such as create, update, delete. Then, an interested party that has subscribed to this event can consume and process it. It is always possible to handle RAP business events locally, that is, in the same system. To make business events visible for external event handlers, they need to be exposed through event bindings.
Business Object's behavior and run time implementation

A business object (BO) represents an entity of the data model. A RAP BO can either consist of a single node (Simple BO) or of a hierarchy of nodes (Composite BO). An example for a Composite BO is a document that consists of a header (root node) and items (child node).

The behavior of a BO defines operations that can be executed on the data, for example the standard operations Create, Update, Delete (CRUD), but also specific actions and functions.

It also provides feature control (for example, the definition which data is mandatory and which is read-only), concurrency control (for example, the handling of locks), and authorization control.

Business service - consisting of service definition and service binding along with Web API lifecycle and tool support

In the context of the ABAP RESTful application programming model, a business service is a RESTful service that can be called by a consumer. It is defined by exposing its data model together with the associated behavior. It consists of a service definition and a service binding.

The service definition is a projection of the data model and the related behavior to be exposed, whereas the service binding defines a specific communication protocol, such as OData V2 or OData V4, and the kind of service to be offered for a consumer. This separation allows the data models and service definitions to be integrated into various communication protocols without the need for reimplementation.

Typical Development Flow main steps - Provide Database Tables, Define the Data Model, Define and Implement the Behavior, Project the RAP Business Object and provide service specific Metadata, Define the Service, and Bind the Service and Test the Service

Developing a RAP application consists of the following main steps:

  1. Provide Database Tables

    Developing a RAP application starts with providing the database tables. Depending on the development scenario, these can be existing tables, legacy tables, or tables created specifically for this application.

  2. Define the Data Model

    The data model of the Business Object is defined with CDS Views. Depending on whether it is a simple or a composite BO, one or more CDS Views are required. In case of a composite BO, this is also the place where you define the entity hierarchy.

  3. Define and Implement the Behavior (Transactional apps only)

    The behavior of a RAP BO is defined in a repository object called CDS Behavior Definition. Usually, the behavior of a RAP BO also requires some additional logic which is implemented in a certain type of global ABAP class, called a Behavior Pool. For a non-transactional application, for example, a list report, the behavior definition or implementation can be omitted.

  4. Project the RAP Business Object and provide service specific Metadata

    The projection of the RAP BO consists of a data model projection, and, if a behavior has been defined, a behavior projection. To define a projection, you create one or more CDS projection views, a type of CDS View, and a Behavior Projection, a type of behavior definition. For UI services, the projection view(s) can be enriched with UI-specific metadata. To support future extensibility of the application, we recommend placing the service-specific annotations in metadata extensions.

  5. Define the Service

    In RAP, a service is defined by creating a Service Definition. The service definition references the projection views and specifies which of them can be exposed, that is, which of them are visible for the service consumer.

  6. Bind the Service and Test the Service

    To specify how the service can be consumed (UI or Web API) and via which protocol (OData V2 or OData V4), a service binding is needed. For UI services, a Preview is available.

Repository Objects for RAP

When expanding the content of an ABAP Development Package in the Project Explorer of ADT, the repository objects are found in different categories of repository objects.

The database tables, along with the included structures, data elements, and domains needed for their definition, are found in the category Dictionary.

The repository objects defining the data model, interface, and projection views, are found in the Core Data ServicesData Definitions node. According to the recommended naming pattern, the data model views can have a letter "R" (for Restricted), the projection views for the interface a letter "I" (for Interface), and the projection views for the projection a letter "C" (for Consumption).

The repository objects for the definition and projection of the RAP BO behavior are located in Core Data ServicesBehavior Definitions. Again, the letters "R", "I", and "C" can help to distinguish between repository objects for definition, interface, and projection.

Service Definitions and Service Bindings have their dedicated subnodes under the Business Services category.

The Behavior Implementation is done in behavior pools, which are global ABAP classes that fulfill certain requirements. Like all global ABAP classes, they can be found in Source Code LibraryClasses. To make behavior pools distinguishable from other ABAP classes, the naming pattern requests their names to start with "BP_" or "<namespace>BP_" instead of the usual "CL_" or "<namespace>CL_" for ordinary ABAP classes.

Note

CDS Access Controls and CDS Metadata are discussed later in this course.

The Business Scenario

Business Scenario based on flight data model

The Business Scenario in this course is based on the flight data model, which has been used in ABAP documentation and training for many years.

For this course, we introduce new entities to the model, Flight Travel that a customer books at a Travel Agency. The Flight Travel consists of several Travel Items, for example bookings on several flights (a flight and a return flight or a flight and a connecting flight).

To make things easier, we start with Flight Travel as a simple BO that is not composite. Later in the course, we introduce the Travel Agency.

Outline of the Course

The outline of the course is as given below:

  1. Step 1 – Read-Only App (Package /LRN/S4D437_SOLUTION_A)
    • OData UI Service for non-transactional app
    • Data Model, Projection, and Business service
  2. Step 2 – Transactional App with Action (Package /LRN/S4D437_SOLUTION_B)
    • Behavior (definition, implementation, projection)
    • Concurrency control and authorization control
  3. Step 3 – EnableDirectEditing(Package /LRN/S4D437_SOLUTION_C)
    • Update and create operations (managed)
    • Value helps, Input checks, dynamic default values, dynamic feature control
  4. Step 4 – Draft-Enabled App (Package /LRN/S4D437_SOLUTION_D)

    Draft-Enable the Business Object

  5. Step 5 – Composition(Package /LRN/S4D437_SOLUTION_E)

    Add child entity Travel Item

  6. Step 6 – Unmanaged Save (Package /LRN/S4D437_SOLUTION_F)

    Reuse existing code to persist Travel Items on the database

  7. Step 7 – Business Events (Package /LRN/S4D437_SOLUTION_G)

    Raise and handle a Business Event TravelCreated

  8. Step 8 – Extensions (Package /LRN/S4D437_SOLUTION_H)
    • Enable extensibility
    • Extend Travel Items with a field for the booking class

We use the ABAP RESTful application programming model (RAP) to build an OData UI service for Flight Travels and preview the OData UI Service in a generated app that is based on the List Report Floorplan of SAP Fiori elements.

First, we develop an OData Service for a non-transactional, read-only app that displays a list and a detail page for flight travels.

Then, we add behavior to the business object, namely an action that the user can execute by pressing a button on the UI. We add concurrency control and authorization control to ensure data consistency and make sure that users only cancel travels for which they have the required authorization.

Next, we enable direct editing by the user. We discuss value helps, implement input checks, provide dynamic default values, and we discuss how to enable or disable editing dynamically.

In a next step, we enable draft-handling, so that the users of the app can interrupt and resume editing and don't lose their work in case of network failures.

By introducing a child entity Travel Item, we turn our simple business object into a composite business object. At first, we let the framework write the travel items to the database. Then we extend the BO with an unmanaged save implementation to reuse existing code for this purpose.

As an example for the raising and handling of Business Events in RAP, we let the BO raise an event TravelCreated whenever a new travel instance is created.

Finally, we make our app extensible and illustrate how it can be used to extend the Travel Items with a field for the booking class.

Read-only App
Data model definition diagram with Data Model views and Database tables highlighted

To define the data model, we create a database table and a CDS View entity.

Define a CDS-Based Data Model

In this exercise, you create copies of the repository objects that define a CDS-based data model.

Note

In this exercise, replace ## with your group number.

Template

Repository Object TypeRepository Object ID
Database Table Definition/LRN/437T_TRAVEL
Data Definition/LRN/437T_R_TRAVEL
ABAP Class/LRN/CL_437T_TRAVEL_FILL

Solution

Repository Object TypeRepository Object ID
Database Table Definition/LRN/437A_TRAVEL
Data Definition/LRN/437A_R_TRAVEL

Prerequisites

If you want to do the exercises as described in this course, you have to book the dedicated hands-on practice system. Follow this link for details: https://learning.sap.com/practice-systems/building-transactional-apps-with-the-abap-restful-application-programming-model.

In addition to the ABAP Service Instance URL, which you will receive during the booking process, you need a local installation of the Eclipse IDE with the ABAP Development Tools plug-in installed on top. Follow this link for a step-by-step instruction https://developers.sap.com/tutorials/abap-install-adt.html.

Task 1: Prepare the Project

In Eclipse, create an ABAP Cloud project and add package /LRN/S4D437_EXERCISE to the list of favorite packages. In the ABAP Cloud project, create a new package under the super package ZLOCAL (suggested name: ZS4D437_##) and add this package also to the favorite packages.

Steps

  1. Open Eclipse, switch to the ABAP perspective and create an ABAP Cloud project.

    1. Open Eclipse.

    2. Choose WindowPerspectiveOpen PerspectiveOther....

    3. In the dialog box, double-click ABAP.

    4. Choose FileNewABAP Cloud Project.

    5. Proceed as follows on the New ABAP Cloud Project dialog that appears:

      If you have been given the ABAP Service Instance URL:

      1. Copy and paste this URL in the corresponding field on the dialog.
      2. Choose Next.

      If you have been given a file containing the Service Key:

      1. Select the Extract link on the dialog.
      2. Choose Import... and select the file with the Service Key.
      3. After importing click Copy to Clipboard to copy the Service Instance URL.
      4. Choose Close.
      5. In the top of the popup box in the ABAP Service Instance URL:* field, paste the ABAP Service Instance URL with the key combination Ctrl + V.
      6. Choose Next.
    6. Choose Open Logon Page in Browser.

    7. You will be prompted to logon to the system.

      Enter the user and password that you used to register to SAP Learning Hub.

    8. When you see the message, You have been successfully logged on, close the browser window and return to Eclipse.

    9. To finish creating the project, choose Finish.

  2. Add package /LRN/S4D437_EXERCISE to the list of Favorite Packages.

    1. In the Project Explorer on the left, expand your ABAP Cloud project.

    2. Right-click Favorite Packages and choose Add Package....

    3. In the search field, enter /LRN/S4D437.

    4. From the list of matching items, select /LRN/S4D437_EXERCISE and choose OK.

  3. In your ABAP Cloud project, create a new package with the attributes listed in the table. When prompted for a transport, choose the transport request in which you are involved. If no transport request is listed, create a new request.

    FieldValue
    NameZS4D437_##.
    DescriptionRESTful Application Programming
    Add to favorite packagesChecked
    SuperpackageZLOCAL
    Package TypeDevelopment
    Software ComponentZLOCAL
    Application ComponentLeave this field blank.
    Transport LayerLeave this field blank.
    1. In the Project Explorer, right-click on your ABAP Cloud project and choose NewABAP Package.

    2. Enter the package name ZS4D437_## where ## is your group number.

    3. Enter the description RESTful Application Programming.

    4. Select the Add to favorite packages checkbox.

    5. Enter the superpackage ZLOCAL.

    6. Ensure that the Package Type is set to Development.

    7. Choose Next.

    8. Ensure that the Software Component is set to ZLOCAL.

    9. Ensure that the Application Component is empty.

    10. Ensure that the Transport Layer is empty.

    11. Choose Next.

    12. Check if there is a transport request listed under the option Choose from requests in which I am involved. If so, choose this option. If the list is empty, choose the option Create a new request and enter a request description, for example, ABAP Exercises.

    13. Choose Finish.

Task 2: Copy a Database Table

Create a copy of the database table /LRN/437T_TRAVEL (suggested name: Z##_TRAVEL) and activate it.

Steps

  1. In the Project Explorer, navigate to the /LRN/437T_TRAVEL database table in the /LRN/S4D437_TEMPLATE package.

    1. In the Project Explorer, expand node /LRN/S4D437_EXERCISE/LRN/S4D437_TEMPLATEDictionaryDatabase Tables.

  2. Create a copy of the database table and place it in your package ZS4D437_##.

    1. Right-click /LRN/437T_TRAVEL and select Duplicate....

    2. Enter the name of your own package and the suggested name for the new database table. Choose Next.

    3. Select the same transport request as before and choose Finish.

  3. Activate the new database table.

    1. In the Eclipse toolbar, choose Activate or press Ctrl + F3.

Task 3: Fill the Database Table

Create a copy of ABAP class /LRN/CL_437T_TRAVEL_FILL (suggested name: ZCL_##_TRAVEL_FILL). Specify the name of your database table as the value of the c_travel_table constant. Then activate and execute the class.

Steps

  1. Create a copy of ABAP class /LRN/CL_437T_TRAVEL_FILL and place it in your package ZS4D437_##.

    1. In the Project Explorer view, locate class /LRN/CL_437T_TRAVEL_FILL in package /LRN/S4D437_TEMPLATE and right-click it to open the context menu.

    2. From the context menu, select Duplicate....

    3. Enter the name of your package and the name for the copy, then choose Next.

    4. Assign the new object to a transport request and choose Finish.

  2. Change the value of the c_travel_table constant to the name of your database table.

    1. Scroll down to the code row starting with CONSTANTS c_travel_table.

    2. In the literal after VALUE, replace ## with your group number.

  3. Activate the ABAP class and execute it as a console application.

    1. Press Ctrl + F3 to activate the development object.

    2. Press F9 to execute the ABAP class as a console application.

  4. Open your database table in the Data Preview tool, and confirm that it contains data.

    1. Right-click anywhere in the source code of the database table definition and choose Open withData Preview, or press F8.

Task 4: Copy a Root View Entity

Create a copy of data definition /LRN/437T_R_TRAVEL (suggested name: Z##_R_TRAVEL). Adjust the view definition to read from your database table Z##_TRAVEL.

Steps

  1. Create a copy of data definition /LRN/437T_R_TRAVEL (suggested name: Z##_R_Travel), assign it to your own package and use the same transport request as before.

    1. In the Project Explorer view, locate the data definition /LRN/437T_R_TRAVEL in the /LRN/S4D437_TEMPLATE package and right-click it to open the context menu.

    2. From the context menu, select Duplicate....

    3. Enter the name of your package and the name for the copy. Choose Next.

    4. Assign the new object to a transport request and choose Finish.

  2. Edit the data definition. Adjust the view name to use a mixture of upper case and lower case (Z##_R_Travel) and make the view read from your own database table.

    1. Adjust the code as follows:

      Code Snippet
      12
      define root view entity Z##_R_Travel as select from z##_travel
  3. Activate the data definition.

    1. In the Eclipse toolbar, choose Activate or press Ctrl + F3.

  4. Test the CDS view by opening it in the Data Preview tool.

    1. Right-click anywhere in the source code of the data definition and choose Open WithData Preview or press F8.