Now accepting guest editorial from SAP, Oracle, Workday and ServiceNow practitioners.Pitch a guide
The Sign-Off Table

Lesson 4 of 5

Business events

10 min

Listen to this lesson

0:00 / 7:17

When a fleet customer's core return agreement is closed, three things should happen elsewhere: finance refunds any remaining deposit, the customer portal shows the agreement as closed, and the returns warehouse stops expecting cores. The old ECC solution called each of these directly from the save logic. Every new consumer meant changing the agreement code, and a failure in one consumer could block the save. RAP business events decouple the provider from its consumers.

What a RAP business event is

SAP defines a RAP business event as a data record that expresses a significant change in the state of a RAP BO entity. Interested parties subscribe and process it; the provider does not know or wait for them. The payload always includes the instance key and can carry more information through a parameter. SAP's documentation currently allows events only in the root entity of a managed or unmanaged BO; they can be added in BDEF extensions and reused in interface BDEFs.

  1. DeclareIn the BDEF: event agreementClosed parameter ZD_CMC_AgreementClosed (a CDS abstract entity with customer, refund amount and currency)
  2. RaiseRAISE ENTITY EVENT in the save phase, recommended in save_modified with additional save for managed BOs
  3. BindAn event binding maps the event to an event type that consumers can subscribe to
  4. Consume locallyAn event handler class in the same system processes it asynchronously
  5. Consume remotelyConfigured event channels pass it to an event broker for other systems and BTP apps
From declaration to consumption for Contoso's agreementClosed event.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-303

Declaring and raising

In the behavior definition, Kenji declares event agreementClosed parameter ZD_CMC_AgreementClosed;. A flat parameter must be a CDS abstract entity; a deep parameter uses an abstract behavior definition with hierarchy for nested payloads. Because the BO is managed, he adds with additional save and raises the event in the saver's save_modified method, only for agreements whose status changed to CLOSED in this transaction: RAISE ENTITY EVENT zr_cmc_coreagreement~agreementClosed FROM ... with the key and the payload values.

Raising in the save phase matters. An event raised earlier, during interaction, could announce a change that is later rejected by a validation or discarded with the draft. Raised during save, it describes something that was actually committed.

Raised in the save phase, agreementClosed describes only changes that were really committed, and consumers process it later on their own.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-303
VariantSyntax ideaUse
Business eventevent name [parameter Entity]Announce a significant state change to any subscriber
Deep payloadevent name deep parameter AbstractBDEFSend header and items in one event
Derived eventmanaged event name on baseEvent parameter EntitySame trigger, different payload for a different audience; raised automatically with the base event
Event for side effectsevent name for side effectsOnly to trigger a UI side effect when something changes in the background

Event variants in SAP's behavior definition language. Check availability for your release.

Consuming events

Inside the same system, a RAP event handler class is declared FOR EVENTS OF the BO, with a local class inheriting from CL_ABAP_BEHAVIOR_EVENT_HANDLER whose methods are declared FOR ENTITY EVENT. SAP's cheat sheet notes that these handler methods are called asynchronously, and that database changes in a handler need the transactional phase handled correctly (class CL_ABAP_TX). For other systems and side-by-side apps, the event binding gives the event a type, and SAP's event infrastructure forwards it through configured channels to an event broker, such as the Event Mesh capability of SAP Integration Suite (formerly the standalone SAP Event Mesh) or SAP Integration Suite, advanced event mesh. In SAP S/4HANA Private Edition and on-premise the channel is set up in the Enterprise Event Enablement framework (transaction /IWXBE/CONFIG); the exact setup depends on your release and landscape.

Because the provider’s save never waits for consumers, each consumer must be idempotent and its failures must have an owner.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-303
Provider: core return agreement BORaises agreementClosed once, at save, and knows nothing about consumers
Event binding and channelMaps the event to an event type and publishes it
ConsumersDeposit refund handler in S/4HANA; customer portal on SAP BTP; warehouse notification
MonitoringEvent and channel monitoring to see what was sent, delivered or failed
Decoupling with events: adding a consumer does not change the provider.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-303

What would you do?

Dan, the finance process owner, wants refunds to start whenever an agreement is closed. A developer proposes calling the refund BAPI directly from the agreement's save_modified method. What should Kenji recommend?

Key points
  • A RAP business event announces a significant state change; consumers subscribe and process it independently.
  • Declare it in the root's BDEF, optionally with a CDS abstract entity parameter; raise it with RAISE ENTITY EVENT at save.
  • An event binding maps the event to an event type; local handlers run asynchronously.
  • Design consumers to be idempotent and monitored; events do not make consumers part of the save.

Check your understanding · not graded

Lesson check

  1. 1. Where does SAP recommend raising RAP business events in a managed BO?

  2. 2. What must a flat event parameter refer to?

  3. 3. What is needed after an event is created and raised so consumers can subscribe?

  4. 4. Why should event consumers be idempotent?