Now accepting guest editorial from SAP, Oracle, Workday and ServiceNow practitioners.Pitch a guide
The Sign-Off Table

Lesson 1 of 5

RAP architecture: data model, behavior and service

10 min

Listen to this lesson

0:00 / 20:03

The ABAP RESTful Application Programming Model (RAP) is SAP's programming model for transactional apps and APIs in ABAP Cloud. If CDS answers "what is the data", RAP answers "what can you do with it, and how is it exposed". SAP Learning summarizes RAP as built on CDS, a service model infrastructure and ABAP-based application services, producing SAP HANA-optimized OData services for Fiori apps and Web APIs. Every SAP Fiori elements app you build on SAP S/4HANA with ABAP Cloud follows this structure, so testers who understand it can read a defect and know which layer to look at.

Business serviceService definition (what is exposed) and service binding (which protocol: OData V2 or V4, UI or Web API)
ProjectionCDS projection views (C_) and a projection behavior definition tailor the BO for one service
BehaviorBehavior definition (BDEF) declares operations; the ABAP behavior pool implements the logic
Data modelCDS view entities (R_ root and child entities) linked by compositions
PersistenceDatabase tables, for example Contoso’s ZCMC_CORE_AGR and ZCMC_CORE_AGI
The RAP layers from table to service, as SAP’s RAP documentation describes them.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-202

The RAP business object

A RAP business object (BO) represents a real-world entity with its data and behavior. Its data is a tree of CDS entities: one root entity, defined with define root view entity, and child entities linked by compositions. Its behavior is declared in a behavior definition (BDEF), which by convention has the same name as the root entity, and implemented in an ABAP behavior pool, a special class pool typically prefixed BP_, whose handler code sits in the Local Types section in ADT. Consumers read and change the BO through the Entity Manipulation Language (EML) in ABAP, or through OData from a UI.

Contoso’s RAP business object is a tree: one root entity for the agreement and a composition child for its items, each over its own custom table.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-202

Contoso’s first RAP app

Maria's order-to-cash team maintains core return agreements today with an old maintenance screen that came across in the conversion. Kenji's team will replace it with a RAP app in the ABAP Cloud software component ZCMC_CLOUD: a Fiori elements list and object page where key users create and change agreements, add items, and close an agreement when the fleet customer ends the program. Following SAP's naming guide, the objects are named as in the table below.

ObjectNameRole
Root view entityZR_CMC_CoreAgreementAgreement header over ZCMC_CORE_AGR
Child view entityZR_CMC_CoreAgreementItemAgreement items over ZCMC_CORE_AGI
Behavior definitionZR_CMC_CoreAgreementSame name as the root entity
Behavior poolZBP_R_CMC_COREAGREEMENTValidations, determinations, actions
Projection views and BDEFZC_CMC_CoreAgreement, ZC_CMC_CoreAgreementItemShape the BO for the UI service
Service definitionZUI_CMC_COREAGREEMENTExposes the projections
Service bindingZUI_CMC_COREAGREEMENT_O4OData V4, UI

Contoso’s core return agreement app (illustrative names following SAP’s RAP naming conventions).

  1. User saves in the Fiori appOData V4 request to the published service
  2. RAP runtimeRoutes the request to the BO through the projection
  3. Interaction phaseCreate or update lands in the transactional buffer; on modify determinations run
  4. Save sequenceOn save determinations and validations run; any failure rejects the whole buffer
  5. PersistManaged BO writes ZCMC_CORE_AGR and ZCMC_CORE_AGI
  6. ResponseMessages and the saved data return to the UI
What happens when Maria saves an agreement.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-202

Two phases you must understand

RAP separates the interaction phase, in which operations change data in the transactional buffer, from the save sequence, in which the buffer is checked and written to the database. SAP's cheat sheet stresses the consequence: when a validation rejects inconsistent data, the entire transactional buffer is rejected, including instances without errors. That all-or-nothing rule is what keeps data consistent, and it is also why a tester sometimes sees a save fail because of an item they did not touch.

EML deserves a sentence of its own because tests use it constantly. READ ENTITIES and MODIFY ENTITIES read and change BO instances in the transactional buffer; COMMIT ENTITIES triggers the save sequence; ROLLBACK ENTITIES discards the buffer. Each call returns response structures: mapped for keys of new instances, failed for instances that could not be processed and reported for messages. In a Fiori app the RAP runtime issues the commit for you; in an ABAP program or a test you call it yourself.

EML changes land in the transactional buffer; COMMIT ENTITIES runs the save sequence, which writes everything or nothing.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-202

What would you do?

During CMQ testing, Maria saves an agreement with three items. Item 2 has a deposit of zero, which a validation forbids. What should she expect, and what should Priya's team record?

Key points
  • RAP layers: persistence, CDS data model, behavior, projection, business service.
  • A RAP BO has one root entity and child entities linked by compositions.
  • The BDEF declares behavior; the ABAP behavior pool (BP_) implements it.
  • Changes go to the transactional buffer, then the save sequence checks and persists them.
  • A failed validation rejects the whole buffer: all or nothing.

Check your understanding · not graded

Lesson check

  1. 1. Which statement defines the top entity of a RAP business object?

  2. 2. Where is a RAP BO’s behavior implemented?

  3. 3. What happens to error-free instances when a validation rejects one instance during save?

  4. 4. Which artifact decides whether a service is exposed as OData V2 or V4?