Skip to content

Lesson 19 Companion — RAP Business Events Reference ​

Start with the simple idea ​

When a customer creates an order, the Online Order application saves it. A RAP Business Event lets the application announce that the order was created. Other components can react to that announcement without being called directly by the Online Order application.

In Lesson 19, our separate component is a local warehouse listener. It reacts by writing a row to a log table. The business concept is more important than any one line of ABAP: a command asks for an action; an event reports an occurrence.

text
Create Order → Managed RAP Save → OrderCreated → Local Handler → Event Log

This reference is independent of Reservation, Support Issue and Checkpoint 4.


1. Terms in one table ​

TermPlain-language meaningOur example
CommandRequest to do somethingCreate an order
Business eventAnnouncement that something happenedOrderCreated
ProducerComponent that announces itOnline Order RAP BO
ConsumerComponent that respondsLocal event handler
Event keyWhich object it happened toOrderUuid
Event payloadAdditional useful detailsItemName
Local event handlerEvent subscriber in the same systemZCL_ORDER_EVT_###

2. Object inventory ​

The manually created objects are:

text
ZPKG_L19_###           package
ZONLINESHOP_###        active order table
ZA_ORDER_EVT_###       abstract entity for event payload
ZORDEVT_###            consumer log table
ZCL_ORDER_EVT_###      local event handler class

The OData UI service generator creates the root CDS, base BDEF, Behavior Pool, projection, service, and possibly draft objects. Read their actual generated names; do not guess.

Reference generator-style names used in code examples:

text
ZR_ONLINESHOP_###       root CDS name
ZrOnlineshop###         root alias in BDEF
ZBP_R_ONLINESHOP_###    illustrative Behavior Pool

If ADT generates other names, substitute them consistently in BDEF, save_modified and handler signatures.


3. The essential BDEF statements ​

Inside the base root behavior body:

abap
event OrderCreated parameter ZA_Order_Evt_###;

In the global managed implementation header:

abap
managed with additional save with full data
implementation in class zbp_r_onlineshop_### unique;
strict ( 2 );
with draft;

Retain other generated BDEF lines. Do not insert this managed header inside define behavior for ... { ... }.

If the generator produces a non-draft variant, preserve its actual valid configuration rather than copying a with draft; directive into a mismatched model.


4. Why with additional save with full data? ​

managed: RAP supplies normal create/update/delete persistence.

with additional save: a custom saver method can run alongside that managed persistence.

with full data: the create-<alias> entries include business fields like Ordereditem, which we want to pass to the event without an additional read.

This is not the same as fully unmanaged RAP or with unmanaged save.


5. The complete core producer snippet ​

In the saver class's generated save_modified method:

abap
METHOD save_modified.

  IF create-zronlineshop### IS NOT INITIAL.

    RAISE ENTITY EVENT ZR_ONLINESHOP_###~OrderCreated
      FROM VALUE #(
        FOR new_order IN create-zronlineshop###
          ( %key            = new_order-%key
            %param-ItemName = new_order-Ordereditem )
      ).

  ENDIF.

ENDMETHOD.

This follows SAP's documented create-event implementation pattern. The root name in RAISE ENTITY EVENT is the globally unique CDS entity name. The create-zronlineshop### structure uses the generated alias.

In the current SAP tutorial, the create event is raised from the late save sequence, not inside the UI or the RAP create request itself.


6. BDEF-derived event row type ​

RAISE ENTITY EVENT ... FROM expects data compatible with:

abap
TYPE TABLE FOR EVENT ZR_ONLINESHOP_###~OrderCreated

You can supply a declared internal table or VALUE #( ... ) inline, as in the guided lesson.

Conceptual shape:

text
%key-OrderUuid
%param-ItemName

The consumer can read the same derived key and payload fields.


7. Abstract entity: what it is and what it isn't ​

abap
@EndUserText.label: 'Order Created Event Payload'
define abstract entity ZA_Order_Evt_###
{
  ItemName : abap.char(25);
}

It is: a reusable type description for the event's additional message data.

It isn't: an active order table, a service entity, or a database lookup.

Do not write SELECT FROM ZA_ORDER_EVT_###.


8. Local event-handler class structure ​

Global class definition:

abap
CLASS zcl_order_evt_### DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC
  FOR EVENTS OF ZR_ONLINESHOP_###.
ENDCLASS.

CLASS zcl_order_evt_### IMPLEMENTATION.
ENDCLASS.

Local Types:

abap
CLASS lcl_order_handler DEFINITION
  INHERITING FROM cl_abap_behavior_event_handler.

  PRIVATE SECTION.
    METHODS on_order_created
      FOR ENTITY EVENT
      IMPORTING created_orders
        FOR ZrOnlineshop###~OrderCreated.
ENDCLASS.

The global FOR EVENTS OF uses the root entity name; the local method's FOR ...~Event can use the alias. SAP's learning course explicitly documents this distinction.

An event-handler subclass may only declare a PRIVATE SECTION. IMPORTING is required conceptually even for a key-only event; with this syntax we spell it out explicitly.


9. Complete local handler implementation ​

abap
CLASS lcl_order_handler IMPLEMENTATION.

  METHOD on_order_created.

    cl_abap_tx=>save( ).

    LOOP AT created_orders ASSIGNING FIELD-SYMBOL(<event>).

      DATA log_entry TYPE zordevt_###.
      CLEAR log_entry.

      log_entry-order_uuid = <event>-%key-OrderUuid.
      log_entry-item_name = <event>-%param-ItemName.
      GET TIME STAMP FIELD log_entry-received_at.

      MODIFY zordevt_### FROM @log_entry.

    ENDLOOP.

  ENDMETHOD.

ENDCLASS.

This is an asynchronous consumer running in its own context, not an ordinary class method called by the producer. SAP's September 2026 tutorial calls CL_ABAP_TX=>SAVE( ) before writing directly to an independent log table to close the active RAP modify phase.

MODIFY makes the demo one-log-entry-per-order: if the same event is handled again, the same key is updated rather than creating another row. For production systems, treat retries, error logging and event idempotence explicitly.

No COMMIT WORK is added.


10. The two tables have different owners ​

text
ZONLINESHOP_### → RAP-managed business persistence
ZORDEVT_###     → separate local-consumer demo log

The event handler may write to its own log table. It should not bypass RAP by modifying ZONLINESHOP_### directly.


11. What we verify in Data Preview ​

TestZONLINESHOP_###ZORDEVT_###
Draft created, not activatedNo new active rowNo new receipt
New order activatedNew active rowReceipt eventually appears
Existing order updatedExisting row changesNo new OrderCreated receipt
Display/read onlyNo new active rowNo new receipt

The active order UUID and event log UUID should match.

Note: the order created before event activation is not retroactively published.


12. Why not use %control in this lesson? ​

We detect create, not a transition such as Status N → C.

The additional-save create-<alias> table tells us which new instances were created. No comparison of an old and new status is needed, and we do not need a %control-Status condition.

This makes Business Events easier to introduce than the previous Reservation Confirm scenario.


13. Draft: one sentence to remember ​

Draft editing is not the final business operation. With the generated Draft application, Save/Activate is the point to check active order persistence and the event's processing.

TABLE FOR EVENT types do not expose %is_draft or %tky; those are not a way to publish events for draft instances.


14. Local vs remote consumption ​

Local:

text
Same ABAP system
RAP producer → local event-handler class

Remote:

text
RAP producer → Event Binding → event infrastructure → remote subscriber

Event Binding is not Service Binding. The first is for remote event publication; the latter exposes OData APIs.

Remote consumption and Event Mesh provisioning are not mandatory for this lesson.


15. Release-contract nuance ​

SAP recommends stable, released interfaces for reusable integration APIs and supports C1/C2 release concepts. The official RAP Learning examples and the September 2026 Online Shop tutorial also show a local event handler connected directly to the custom RAP root inside a teaching setup.

Do not turn C1 release into a prerequisite for this basic local demonstration. Production interface release and compatibility are a later Clean Core concern.


16. When would a real company use this? ​

Possible follow-ups to OrderCreated:

  • inform a warehouse fulfillment system;
  • initiate a notification workflow;
  • update a downstream analytics model;
  • begin delivery planning.

The Online Order provider should not have to import and call each consumer's code directly.


17. Failure investigation ​

SymptomLikely layer
Order isn't savedGenerated RAP app / Draft / service
No save_modifiedAdditional-save header or saver generation
Event table emptycreate-<alias> and save sequence
Event raised but no logHandler activation, delivery, consumer errors
Handler enters but direct SQL failsCL_ABAP_TX=>SAVE( ), table access, key mapping
ItemName blankAbstract entity, %param mapping
Syntax complains about event nameGlobal CDS entity name vs alias

SAP runtime tools and authorizations differ among shared Trial instances. Record the actual error rather than telling students to keep rebuilding objects.


18. Code review checklist ​


19. Primary SAP references ​

Scope of validation: patterns compared against published SAP examples. Runtime activation and asynchronous event delivery remain to be checked in the actual instructor/student ABAP environment.