ABAP RESTful Application Programming Model (RAP)

Introduction

The ABAP RESTful Application Programming Model (RAP) represents a significant advancement in SAP's development ecosystem, designed to streamline the creation of modern business applications and services. By leveraging RESTful services and optimizing for SAPHANA, RAP enables developers to efficiently build applications that meet contemporary business requirements. This framework is particularly beneficial for those working with SAP S/4HANA and SAP Business Technology Platform (BTP) ABAP environments, as it simplifies the integration with various SAP solutions through OData services. RAP's architecture supports both cloud and on-premise deployments, making it a versatile tool for developers seeking to modernize their ABAP skills and enhance application development efficiency.

Understanding the ABAP RAP Architecture

The ABAP RESTful Application Programming Model comprises three main layers:

  • Data Modeling and Behavior
  • Business Service Provisioning
  • Service Consumption

Data modeling and behavior - this layer focuses on defining domain-specific business objects using Core Data Services (CDS) and transactional behavior. CDS enables developers to create robust data models that encapsulate the structure and relationships of business entities, while transactional behavior defines how these entities interact within the application.

Business service provisioning - at this layer, projection views and their associated behaviors are defined to highlight specific aspects of the data model. These are then exposed as business services via the OData protocol, allowing for standardized and efficient data exchange between different components of the application.

Service consumption - theservice consumption layer facilitates the use of various OData services andOData Web APIs, enabling seamless integration and interaction with externalapplications. This layer ensures that business services can be easily consumedby different clients, such as SAP Fiori applications, to provide a unified userexperience across the enterprise.

To illustrate the interaction between these layers, consider a scenario where a business object representing an order is defined in the data modeling layer. The business service provisioning layer would then expose specific aspects of this order, such as order status or customer details, as an OData service. Finally, the service consumption layer would allow an SAP Fiori application to consume this service, displaying the relevant order information to the user.

What is a Business Object in ABAP RAP?

A Business Object (BO) represents a real-world entity (like an order, product, or employee) and encapsulates:

  1. Data Model: Defined using Core Data Services (CDS), which outlines the structure of the business object, including its fields and relationships. The relationships between business objects can be established through composition or association, with composition being a tighter relationship where the child entity cannot exist independently of the parent.
  2. Behavior Definition: Specified using the Behavior Definition Language (BDL), this defines the operations that can be performed on the business object, such as create, update, and delete, along with validations, determinations, and actions.
  3. Behavior Implementation: Implements the custom logic for the behavior. This involves implementing methods for actions, determinations, and validations as specified in the behavior definition, allowing developers to customize and extend the behavior of their business objects according to specific business requirements.

Business objects are categorized into two primary types based on their implementation: managed and unmanaged

Managed business objects - these objects are ideal for new applications where all essential parts must be developed from scratch. The RAP framework provides out-of-the-box support for transactional processing, including standard CRUD (Create, Read, Update, Delete) operations. Developers only need to specify these operations in the behavior definition to obtain a ready-to-run business object. The managed RAPBO provider handles the technical implementation aspects, such as locking objects for changes and managing the transaction buffer, allowing developers to focus on implementing business-specific logic using actions, validations, and determinations.

Unmanaged Business Objects - there is no standard functionality provided by the RAP framework for operations like CRUD. Instead, developers must specify the behavior in the behavior definition and implement it manually

In the ABAP RESTful application programming model, there are two primary methods for interacting with a Business Object:

  1. Via a Business Service: For instance, using an OData UI Service for an SAP Fiori application.
  2. From within ABAP Code: Utilizing the Entity Manipulation Language (EML).

While it is technically feasible to consume a Business Object directly, it is recommended to access Business Object Projections and Business Object Interfaces instead.

Business Object Projection and Interface

BO Projections and Interfaces are essential components in the ABAP RAP framework, enhancing the flexibility and maintainability of business applications.

Business Object Projection: A projection defines a service-specific subset of a business object's data and operations. This allows developers to tailor the data and behaviors exposed by a service to meet the specific needs of different applications or scenarios. For example, a sales application might only require access to customer names and order totals, while a logistics application might need detailed shipping information. By defining projections, developers can ensure that each service provides the right level of detail without exposing unnecessary data.

Business Object Interface: An interface provides a stable and standardized way to access a business object's data and operations. These interfaces are typically released for use in other software components, ensuring that changes to the underlying business object do not affect dependent applications. Interfaces are composed of CDS view entities and behavior definitions, similar to business objects, but are designed to be more abstract and reusable. For instance, an interface for a customer business object might include methods for retrieving customer details or updating addresses, allowing different applications to interact with customer data in a consistent manner.

Similar to a Business Object, both Business Object Projections and Business Object Interfaces are composed of two key components:

  1. CDS View Entities: These are defined in Data Definitions and can include one or more entities.
  2. Behavior Definition: This outlines the behavior of the object or interface.
Draft Handling

RAP supports draft handling, a feature that allows users to temporarily store incomplete data in the database. This capability is particularly useful in scenarios where users need to work on tasks across multiple sessions without losing progress. By enabling draft handling, developers can enhance user experience and productivity by ensuring that users can pick up where they left off, even if they are interrupted or need to switch between different tasks.

For example, in a sales order application, draft handling might allow a user to start creating an order, save it as a draft, and then return to it later to complete the details. This feature is especially beneficial in complex business processes where data entry might be time-consuming or require multiple steps.

Event-Driven Architecture

RAP natively supports event-driven architecture through business events, which can trigger follow-up processes when significant changes occur to a business object. This capability facilitates asynchronous communication within or across systems using SAP Event Mesh, allowing for more dynamic and responsive application behavior.

For instance, when a customer places an order, a business event could be triggered to notify the logistics team, initiate shipping processes, or update inventory levels. This event-driven approach enables real-time responses to business events, enhancing overall system efficiency and reducing manual intervention.

By leveraging event-driven architecture, developers can create applications that are more responsive to changing business conditions, improving both internal operations and customer satisfaction.

Step-by-step guide to creating a RAP application

Step 1: Set up your development environment

  1. Install Eclipse with ABAP Development Tools (ADT): This is the primary tool for developing RAP applications.
  2. Connect to your SAP system: Configure your Eclipse environment to connect to your SAP BTP ABAP Environment or SAP S/4HANA system.

Step 2: Create Database Tables

  1. Define your data structure: Determine the fields and structure of your database tables based on your application's requirements.
  2. Create tables in eclipse: Use the Eclipse ADT to create the necessary database tables.

Step 3: Define the Data Model

  1. Create CDS views: Use CDS to define the data model of your business object.
  2. Define associations and annotations: Use annotations to specify UI elements, filters, and other metadata.

Step 4: Define and Implement Behavior

  1. Create a behavior definition: Use the Behavior Definition Language (BDL) to define the transactional behavior of your business object.
  2. Implement behavior logic: Write ABAP code to implement the behavior logic using the Entity Manipulation Language (EML) in the local classes of the ABAP behavior pool.

Step 5: Project the Business Object

  1. Create a projection view: Project a subset of fields from your data model to optimize for specific services.
  2. Define behavior projection: If applicable, project a subset of behaviors to limit exposed operations.

Step 6: Define the Service

  1. Create a service definition: Specify which CDS entities to expose through your service.
  2. Bind the service: Bind your service definition to a protocol like OData V2 or V4.

Step 7: Test and Publish the Service

  1. Preview the service: Use the preview functionality in Eclipse to test your service.
  2. Publish the service: Once satisfied, publish your service to make it available for consumption. 

Conclusion

ABAP RESTful Application Programming Model (RAP) is a powerful tool for SAP developers, offering streamlined development processes, seamless integration with SAP solutions, and optimization for SAP HANA. Its ability to support both managed and unmanaged business objects, along with features like draft handling and event-driven architecture, makes it ideal for building modern business applications that meet evolving business needs. As SAP continues to evolve its ecosystem, RAP is poised to play a crucial role in helping developers modernize their applications and leverage the full potential of SAP technology. Whether you're developing new applications or enhancing existing ones, RAP provides the flexibility and efficiency needed to stay ahead in today's fast-paced digital landscape. 

Written by
Marek Przygocki

No items found.