Announce a fact without naming every listener

When a parcel is packed, the system may need to update a monitor, write an audit note, or notify another collaborator. An ABAP event lets an event source announce that something happened while registered handlers respond to it.

Declare and raise an event

EVENTS packed EXPORTING VALUE(ev_code) TYPE string.

METHOD finish.
  RAISE EVENT packed EXPORTING ev_code = iv_code.
ENDMETHOD.

Register a handler

METHODS on_packed
  FOR EVENT packed OF lcl_packer
  IMPORTING ev_code.

At runtime, a caller connects a handler object to an event source with SET HANDLER monitor->on_packed FOR packer. The handler receives the event parameter. The event source does not need to hard-code the monitor class.

When events fit

Events help when one occurrence can interest several registered listeners and the publisher should not orchestrate all of them directly. For a required one-to-one call with a value that must be returned, a normal method or interface is usually simpler. Events should not hide essential synchronous control flow.

Practice

Declare the event and compatible handler, raise the event from the source, and register it with SET HANDLER. This brief structural checker focuses on declaration/raise/handler; it does not dispatch ABAP events. Add output for a result message in your chosen program context.

Version note: ABAP event syntax and allowed framework APIs depend on the target release and language version.

Sources

Developer practice · ABAP

Practice: raise and handle a packed event

Declare a packed event, a matching handler, and connect them with SET HANDLER. Set result to a message confirming the handler registration.

Choose your ABAP environment

This choice changes the output pattern checked here: WRITE belongs in a classic executable report, while out->write( ) uses the supplied output reference in an ABAP Cloud class-run method. It does not switch the language version of the other code; check release and API availability in your target system.

Complete the task and include the output statement shown for your selected environment. Variable names can differ if you use them consistently. This browser checker checks structure only; it does not compile or run ABAP.

0 required structures detected · 0 checks