RAP layers
A typical RAP service is built in layers, each with a clear responsibility:
- Interface View (CDS) — technical access to the table, without UI annotations.
- Behavior Definition + Implementation — defines which operations exist (Create, Update, Delete, actions) and their logic.
- Projection View (CDS) — the view consumed by the client (Fiori, API), with
@UIannotations. - Behavior Projection — exposes only the subset of operations that consumer needs.
- Service Definition / Service Binding — publishes the projection view as an OData v2/v4 service.
Behavior Definition
Defines the transactional operations allowed on the entity. This is where draft is enabled, allowing intermediate changes to be saved without committing them to the database until "Save".
managed implementation in class zbp_i_contract_manager unique; strict(2); with draft; define behavior for ZI_CONTRACT_MANAGER alias Contract persistent table zcontract draft table zcontract_d etag master LocalLastChangedAt lock master authorization master ( instance ) { create; update; delete; draft action Edit; draft action Activate; draft action Discard; draft action Resume; draft determine action Prepare; field ( readonly ) ContractId; field ( mandatory ) ContractManager1; determination setDefaults on save { create; } validation validateManager on save { field ContractManager1; } }
Behavior Implementation
The business logic lives in an ABAP class that implements the methods defined in the Behavior Definition. Here, for example, a validation that prevents saving a contract without an assigned manager.
METHOD validateManager. READ ENTITIES OF zi_contract_manager IN LOCAL MODE ENTITY Contract FIELDS ( ContractManager1 ) WITH CORRESPONDING #( keys ) RESULT DATA(contracts). LOOP AT contracts INTO DATA(contract). IF contract-ContractManager1 IS INITIAL. APPEND VALUE #( %tky = contract-%tky ) TO failed-contract. APPEND VALUE #( %tky = contract-%tky %msg = NEW zcx_contract( textid = zcx_contract=>manager_missing ) ) TO reported-contract. ENDIF. ENDLOOP. ENDMETHOD.
Projection and exposing it as a service
The Behavior Projection exposes only what the Fiori consumer needs, and the Service Binding publishes that projection as an OData endpoint that SAPUI5 consumes directly.
projection; strict(2); define behavior for ZC_CONTRACT_MANAGER alias Contract { use create; use update; use delete; use action Edit; use action Activate; use action Discard; use action Resume; }