Appearance
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 LogThis reference is independent of Reservation, Support Issue and Checkpoint 4.
1. Terms in one table
| Term | Plain-language meaning | Our example |
|---|---|---|
| Command | Request to do something | Create an order |
| Business event | Announcement that something happened | OrderCreated |
| Producer | Component that announces it | Online Order RAP BO |
| Consumer | Component that responds | Local event handler |
| Event key | Which object it happened to | OrderUuid |
| Event payload | Additional useful details | ItemName |
| Local event handler | Event subscriber in the same system | ZCL_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 classThe 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 PoolIf 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_###~OrderCreatedYou can supply a declared internal table or VALUE #( ... ) inline, as in the guided lesson.
Conceptual shape:
text
%key-OrderUuid
%param-ItemNameThe 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 logThe 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
| Test | ZONLINESHOP_### | ZORDEVT_### |
|---|---|---|
| Draft created, not activated | No new active row | No new receipt |
| New order activated | New active row | Receipt eventually appears |
| Existing order updated | Existing row changes | No new OrderCreated receipt |
| Display/read only | No new active row | No 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 classRemote:
text
RAP producer → Event Binding → event infrastructure → remote subscriberEvent 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
| Symptom | Likely layer |
|---|---|
| Order isn't saved | Generated RAP app / Draft / service |
No save_modified | Additional-save header or saver generation |
| Event table empty | create-<alias> and save sequence |
| Event raised but no log | Handler activation, delivery, consumer errors |
| Handler enters but direct SQL fails | CL_ABAP_TX=>SAVE( ), table access, key mapping |
| ItemName blank | Abstract entity, %param mapping |
| Syntax complains about event name | Global 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
- Create a RAP Business Event in SAP BTP ABAP Environment — standalone Online Shop generator, full-data additional save and a local event handler; revised September 2026.
- Raising and Handling Business Events — RAP business events and local handling.
- Working with Event Parameters — abstract entities,
%keyand%param. - RAP110 Exercise 11 — alternate SAP workshop implementation.
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.