Guide

RAP and CDS Views — Building Transactional Apps in SAP S/4HANA

Learn how the ABAP RESTful Application Programming Model (RAP) uses CDS Views as its foundation. Covers data modeling, behavior definitions, projection views, service exposure, and implementation types for SAP S/4HANA and BTP ABAP.

What is RAP?

The ABAP RESTful Application Programming Model (RAP) is SAP's recommended programming model for building transactional, draft-enabled, and Fiori-ready applications on SAP S/4HANA and BTP ABAP Environment. Introduced with SAP S/4HANA 1809, RAP replaces older patterns such as BOPF, SEGW (the SAP Gateway Service Builder), and classic Dynpro-based transactions.

RAP is built on three pillars:

  • CDS-based data model — CDS View Entities define the business object structure and its composition hierarchy.
  • Behavior definition (BDEF) — A dedicated artifact that declares transactional capabilities such as create, update, delete, actions, validations, and draft handling.
  • Service exposure — Service definitions and service bindings expose the business object as an OData service consumed by Fiori Elements or custom UIs.

CDS Views in RAP — The Data Model Layer

Every RAP business object starts with a CDS View Entity that serves as the root of a composition hierarchy. The root entity represents the main business object (e.g., a travel booking, a sales order), and child entities are connected via composition associations.

Composition Hierarchy

A typical RAP data model follows a parent-child pattern: the root entity owns one or more child entities, which may in turn own grandchild entities. This composition tree defines the transactional boundary — all entities within the tree are locked, validated, and saved together.

define root view entity Z_R_TravelTP
  as select from /dmo/travel
  composition [0..*] of Z_R_BookingTP as _Booking
{
    key travel_id   as TravelID,
    agency_id       as AgencyID,
    customer_id     as CustomerID,
    begin_date      as BeginDate,
    end_date        as EndDate,
    overall_status  as OverallStatus,
    _Booking
}

The _Booking composition tells the RAP framework that bookings belong to a travel instance and cannot exist independently. The child entity uses association to parent to reference back.

CDS View Entity vs. CDS View

RAP requires the modern CDS View Entity syntax (introduced in ABAP 7.55 / S/4HANA 2020). The older define view syntax is considered legacy and lacks features such as typed literals, improved type inference, and the provider contract clause. For new RAP development, always use define root view entity or define view entity. See our guide on CDS View Types.

Behavior Definition — What Makes RAP Transactional

A CDS View Entity on its own is read-only. The Behavior Definition (BDEF) turns it into a transactional business object. The BDEF is attached to the root CDS entity and declares:

  • Standard operationscreate, update, delete
  • Actions — Custom operations like Approve, Reject, or Copy
  • Determinations — Automatic field calculations triggered on modify or save
  • Validations — Business rule checks executed before persistence
  • Draft handling — Enables users to save incomplete data as drafts
managed implementation in class zbp_r_traveltp unique;

define behavior for Z_R_TravelTP alias Travel
persistent table /dmo/travel
{
  create; update; delete;
  association _Booking { create; }

  field ( readonly ) TravelID;
  determination setTravelID on modify { create; }
  validation validateDates on save { field BeginDate, EndDate; }
}

The keyword managed tells the RAP framework to handle all persistence operations automatically. The behavior implementation class zbp_r_traveltp contains the ABAP logic for determinations, validations, and actions.

Projection Views — The Consumption Layer

While the root CDS entity (prefixed with R_ by convention) defines the complete data model, projection views (prefixed with C_) form the consumption layer. A projection view selects a subset of fields, adds UI annotations for Fiori Elements, and restricts which actions are available.

define root view entity Z_C_TravelTP
  provider contract transactional_query
  as projection on Z_R_TravelTP
{
    @UI.selectionField: [{ position: 10 }]
    @UI.lineItem: [{ position: 10 }]
    TravelID,

    @UI.selectionField: [{ position: 20 }]
    AgencyID,

    CustomerID,
    BeginDate,
    EndDate,

    @UI.lineItem: [{ position: 60 }]
    OverallStatus,

    _Booking : redirected to composition child Z_C_BookingTP
}

The provider contract transactional_query clause marks this projection as suitable for transactional consumption. The @UI annotations control how Fiori Elements renders the list report and object page. For a deep dive into annotations, see CDS View Annotations.

Service Definition and Binding

The final step in exposing a RAP business object is creating a Service Definition and a Service Binding.

Service Definition

define service Z_UI_Travel {
  expose Z_C_TravelTP as Travel;
  expose Z_C_BookingTP as Booking;
}

Service Binding

The service binding assigns a protocol version (OData V2 or V4), a binding type (UI, Web API, or InA), and generates the runtime endpoint. OData V4 is recommended for new projects. For details, see Service Bindings and Service Definitions.

Browse real SAP-delivered service bindings on CDSee: Browse OData Services

Managed vs. Unmanaged vs. Managed with Additional Save

RAP supports three implementation types that determine how persistence is handled:

Implementation TypePersistenceUse Case
ManagedFramework handles all CRUD operationsNew greenfield development — recommended default
UnmanagedDeveloper implements all persistence logicWrapping legacy code, BAPIs, or function modules
Managed with Additional SaveFramework + custom save logicWhen managed persistence needs extra side effects

For most new S/4HANA and BTP ABAP projects, the managed scenario is the right choice. The unmanaged scenario is valuable when you need to wrap existing ABAP logic behind a modern RAP facade.

Finding RAP Examples on CDSee

RAP vs. Legacy Programming Models

AspectRAPBOPFSEGWClassic Dynpro
Data ModelCDS View EntitiesBOPF nodesMPC/DPC modelDDIC structures
UI TechnologyFiori Elements / UI5Fiori ElementsFiori / UI5SAP GUI (Dynpro)
ProtocolOData V2 / V4OData V2OData V2RFC / proprietary
Draft SupportBuilt-inBuilt-inManualNot available
Cloud ReadyYes (BTP ABAP)NoNoNo
RecommendedYes — SAP standardDeprecatedMaintenance onlyLegacy only

For any new development on S/4HANA (2020+) or BTP ABAP Environment, RAP is the clear choice. To learn more about how CDS Views underpin the S/4HANA architecture, start with What Is a CDS View?.