What does it do? RAP event handler methods> must be defined and implemented in the private visibility section> of a local class>, which is implemented in the CCIMP include> of a RAP event handler class>. The local class must inherit from CL_ABAP_BEHAVIOR_EVENT_HANDLER>>. When a RAP business event is raised using a RAISE ENTITY EVENT>> ABAP_EML statement, the RAP event handler methods are called system-locally and processed asynchronously. The following points are relevant concerning the syntax:
RAP event handler methods must be defined as instance methods> using the METHODS > keyword.
The method name meth> can be freely chosen.
der_type> specifies the BDEF derived type>. It is an internal table of type TYPE TABLE FOR EVENT>>. If the event is specified with parameters, the BDEF derived type der_type> contains the keys of RAP BO instances> (%key>>) for which an event has been raised, along with the parameters (%param> >). If the event is specified without parameters, der_type> contains only the keys. If the RAP event handler class is related to a RAP BO interface>, then the keys and parameters are those used in the interface BDEF>.
The name of der_type> can be chosen freely.
The BDEF derived type is passed by reference>. Therefore, instead of just specifying the name of the formal parameter> der_type>, the syntax can also be ... REFERENCE(der_type) ...>.
The methods are implicitly final, and only importing parameters are possible. The specification of the additions FINAL>> and IMPORTING>> is optional.
bdef> specifies the name of the RAP BO root entity>. The events handled by the class must be defined in the BDEF> of that root entity. bdef> can also be the name of an interface BDEF> that exposes events.
The name of RAP BO root entity (or interface BDEF) is followed by a tilde and the (alias) name of the event evt>. For modularization purposes, a single RAP event handler method can handle multiple events. The following code snippet demonstrates the definition of a method that handles three events defined in the BDEF. METHODS on_evt FOR ENTITY EVENT evt1_type FOR bdef~evt1 evt2_type FOR bdef~evt2 evt3_type FOR bdef~evt3.>
Latest notes:
In a RAP event handler class, a RAP business event can be handled only once, i.e. specifying the parameter for an event in event handler methods more than once is not allowed.
Unlike RAP handler methods> and RAP saver methods>, RAP event handler methods do not contain RAP response parameters> as implicit changing parameters.
The syntax ... FOR EVENT ... FOR> for event handler method declarations is obsolete. Using this syntax generates a syntax warning. BEGIN_SECTION VERSION 5 OUT See METHODS, FOR EVENT, FOR> >. END_SECTION VERSION 5 OUT
Method declarations using this syntax are not to be confused with method declarations in the context of non-RAP events>: METHODS, FOR EVENT>>.
When event handler methods are called, they run through their own RAP transaction, i.e. when they are called, the current phase is the RAP interaction phase>. In general, implementations in event handler methods must fulfill the RAP BO contract> to guarantee transactional consistency. Therefore, implementations can be included in the event handler method that are allowed in the RAP interaction phase right away. However, if your use case requires implementations in such a method that are reserved for the RAP save sequence> and must not occur in the RAP interaction phase, for example, database modifications using AB_SQL
In addition to consuming RAP business events locally using RAP handler methods, RAP business events can also be consumed system-externally using the RAP event binding. BEGIN_SECTION VERSION 5 OUT or calling update function modules> END_SECTION VERSION 5 OUT , you must explicitly switch in the event handler method implementation to the RAP save sequence by calling cl_abap_tx=>save( ).>>. Otherwise, a runtime error occurs. For more information, see Ensuring Data Consistency in a RAP Transaction>. NON_V5_HINTS ABAP_HINT_END
ABAP_FURTHER_INFO Development guide for the ABAP RESTful Application Programming Model, section about RAP Business Events>.
ABAP_EXAMPLE_ABEXA The example Local Consumption of RAP Business Events> demonstrates the use of RAP event handler methods. ABAP_EXAMPLE_END