ABAP RAP

ABAP RESTful Application Programming Model

Additional Concepts

  • Draft
  • Layers & Projections
  • Feature Control
  • Custom CDS Entities
  • Virtual Elements
  • Dynamic properties

Error situations

  • Service not updated after a change => bump the binding version or recreate the binding
  • Associated view not visible => expose the view in the Service Definition
  • No browser permission shown before login => try a different browser (e.g., Chrome)
  • Navigation from a user/task list to a single task not shown or not possible => restarting the browser sometimes helps

Draft mode — DRAFT

In Draft mode an object is persisted in a way that allows the user to interrupt editing in the web UI and continue later without losing entered data. Draft instances are stored in a draft table and can be found again via a dedicated search for drafts.

Draft table

The draft table contains the fields of the regular persistence table plus the fields from the include structure sych_bdl_draft_admin_inc. The draft table uses the same key as the main table. Therefore each BO instance can have at most one draft version.

Example: DRAFT support

The RAP generator creates the required artifacts including Draft objects by default.

Draft — key facts

  • Definition: Draft handling in RAP allows users to persist incomplete changes in a draft state without committing them to the main persistent data immediately.
  • Goals:
    • Improve the user experience by allowing partial or interrupted edits to be saved.
    • Avoid inconsistent data states.
  • Draft object: A persistent representation of the transactional buffer which stores the in-progress changes before they are finalized.
  • Automatic locking behavior: Drafts are user-bound and prevent parallel editing of the same draft (status as of Nov 2024 — behavior may evolve).
  • Separation of draft and persistence logic: Changes saved in the draft do not affect the main persistent object until finalization.

Draft lifecycle

  1. Creation of a draft

    • Changes are written to the separate draft table.
    • A quick-fix is available to create the draft table when missing.
  2. Continue editing

    • The user can open and edit the draft at a later time.
  3. Finalization

    • The draft is either:
      • Persisted (changes applied), or
      • Discarded (changes removed).

Projections

  • Definition: Projections are specialized, consumption-oriented views on existing Business Objects in RAP. They allow tailoring the data model and behavior to the needs of a specific application or role.
  • Goals:
    • Simplify data models for particular scenarios.
    • Separate backend logic from UI-specific requirements.
    • Reuse data models across different applications.

When to use projections

If you need role-specific or use-case-specific variants of the same BO (for example different editing rights or different visible fields for different user roles), create projection views on the existing model.

Typical steps when creating projections:

  • Create the projection view(s): define ... as projection on ...
  • Redirect associations to the projection views (e.g. composition children or parent redirects)
  • Project the behavior definition (project actions and semantics)
  • Define the used actions (use ...)
  • Create the Service Definition and Service Binding that expose the projection

Feature Control

All properties in a Behavior Definition can be controlled dynamically, for example the availability of actions.

Declare a controlled action in the Behavior

Mark the action as feature-controlled in the behavior definition:

action (features: instance) cancel result [1] $self;

Implement dynamic decision in ABAP

The Behavior Handler returns the feature state (available / unavailable) during runtime. Example placeholder in ABAP:

METHOD get_features.

	" Implement feature decision logic here and fill the response

ENDMETHOD.

Custom CDS Entities — wrapping ABAP code

Custom CDS entities allow you to provide CDS entities that are implemented in ABAP classes. Implement the interface IF_RAP_QUERY_PROVIDER to supply query results from ABAP.

Example method signature for a query provider implementation:

	METHODS select IMPORTING io_request  TYPE REF TO if_rap_query_request
												io_response TYPE REF TO if_rap_query_response
								 RAISING   cx_rap_query_provider.

Virtual Elements — ABAP-calculated fields

Virtual elements are read-only fields whose values are computed in ABAP. They are useful when a value cannot be derived directly from a database column and must be calculated at runtime.

In the CDS view

@ObjectModel.virtualElement: true
@ObjectModel.virtualElementCalculatedBy: 'ABAP:ZCL_BC_VIRTUAL_ELE'
'' as VirtualFieldName,

In the ABAP class

Implement a class such as ZCL_BC_VIRTUAL_ELE and the required SADL/exit interfaces, e.g. IF_SADL_EXIT_CALC_ELEMENT_READ.

Optional: GET_CALCULATION_INFO before select

If the calculation requires additional fields, implement GET_CALCULATION_INFO to return the list of fields that need to be selected from the DB. These fields are then provided to your calculation logic.

Dynamic properties

Annotation values can be dynamic — not only static literals. Example: hide a facet depending on a CDS field value:

@UI.facet: [{ id: 'TasksToDo',
									purpose:  #STANDARD,
									type:     #LINEITEM_REFERENCE,
									label:    'Tasks to do',
									hidden: #(IsHidden),
									targetElement: '_TasksToDo',
									position: 10 }]

In this example the facet is visible only when the CDS view field IsHidden is empty.