Types of Behavior Definitions in SAP RAP

Types of Behavior Definitions in SAP RAP

SAP RAP

Behavior Definitions (BDEF) define how your RAP Business Object behaves transactionally. The header declares the implementation type, which controls how CRUD, validations, and save logic are handled.

Below is an overview of the main Behavior Definition types in RAP, when to use each, and links to SAP Help documentation for further reading.


1) Managed Behavior Definition (managed)

What it is:
The RAP framework fully manages persistence (CRUD), validations, and the save sequence for your BO. You declare the persistent database table and map CDS fields to DB columns. The framework automatically handles data changes, drafts, and optimistic locking.

When to use:
Use this for most transactional apps where you want RAP to take care of persistence and save logic without writing custom save code.

Example header snippet:

managed;
define behavior for ZI_BILLING_ROOT alias Billing
  persistent table zbilling_root
{
  ...
}

SAP Help Reference:
Managed Behavior Definition - SAP Help


2) Managed Behavior with Save Options (with additional save / with unmanaged save)

What it is:
Variants of managed behavior that allow injecting custom save logic at certain points without fully taking over persistence.

  • with additional save lets you add extra save steps while the framework controls the overall save.

  • with unmanaged save lets you partially control the save sequence, but still use framework persistence for parts.

When to use:
Use when most persistence can be managed by RAP, but you need custom logic during save, e.g., integration calls or special numbering.

SAP Help Reference:
Save Options in Behavior Definitions - SAP Help


3) Unmanaged Behavior Definition (unmanaged)

What it is:
You take full responsibility for all persistence and save logic. You implement the behavior pool class with methods for create, update, delete, and save operations. RAP provides the framework but no automatic persistence.

When to use:
Use when persistence involves external systems, complex distributed transactions, or when full custom control is required.

Example header snippet:

unmanaged implementation in class zbp_billing unique;
define behavior for ZI_BILLING_ROOT alias Billing
{
  implementation in class zbp_billing unique;
  ...
}

SAP Help Reference:
Unmanaged Behavior Definition - SAP Help


4) Projection Behavior Definition (projection)

What it is:
Projections define service-specific behavior on top of a base BO. They control which actions and operations are exposed, and can restrict or rename actions for different consumers.

When to use:
Use when you need multiple service views on the same BO, for example a read-only service vs. a full CRUD service, or roles with limited permissions.

SAP Help Reference:
Projection Behavior Definitions - SAP Help


5) Interface Behavior Definition (interface)

What it is:
An Interface BDEF defines a RAP Business Object (BO) interface that serves as a contract for stable consumption, typically released under the C1 contract. It specifies the behavior included in the interface, allowing for a standardized interaction with the BO.

Key Characteristics:

  • No persistence; not backed by a database table.

  • Defines actions, associations, and events the BO supports.

  • Serves as a stable API contract for consumers.

When to use:
Use Interface BDEFs to expose a stable and consistent API, ensuring consumers rely on defined behaviors without implementation details.

SAP Help Reference:
RAP - Interface Behavior Definition


6) Abstract Behavior Definition (abstract)

What it is:
An Abstract BDEF serves as a typing mechanism for deep parameters in actions or functions. It is based on a CDS abstract entity and does not implement persistence or behavior logic itself. Instead, it provides structure used by other BDEFs.

Key Characteristics:

  • No persistence; not backed by a database table.

  • Defines typed structures for deep parameters in actions/functions.

  • Cannot be used directly; must be extended or implemented.

When to use:
Use Abstract BDEFs to define structured types for deep parameters, ensuring type safety and consistency in your RAP app.

SAP Help Reference:
RAP - Abstract Behavior Definitions


Quick decision guide

BDEF Type Use Case
Managed Most transactional apps needing full RAP persistence and save logic handled automatically.
Managed + Save Options Managed persistence plus custom save steps for specific needs.
Unmanaged Full control over persistence and save logic; for complex or external persistence.
Projection Multiple service views with different access or actions on the same BO.
Interface Define reusable behavior contracts without persistence.
Abstract Base behavior for reuse without persistence implementation.

Tags: #bdef#rap