This series of blogs intends to show in a step-by-step way the different possibilities to use RAP Business Events with Advanced Event Mesh.
Overview
The fourth blog of the RAP Business Events with Advanced Event Mesh series is gonna look at so called derived events. Derived events are events that are derived from other events and are always automatically triggered when that other event is triggered. While standard events can not be customised, derived events us CDS Views to determine the payload of a event. As such they are the ideal choice when the payload of a standard event is not sufficient. Derived events are however limited in their complexity as they only allow flat structures as payloads.
In this blog we’ll be creating a derived event for the standard event “Business Partner Changed” and add two additional fields to its payload.
Note: This blog focuses on S/4HANA On Premise 2023. With this release many events are only accessible through non-released interfaces. As such the ABAP language version “ABAP for Cloud Development” can not be used for the content of this blog.
Finding RAP business event behavior definitions
Before being able to create a derived event you’ll need to find the behavior definition where the standard event is defined. To make it easier to find these behavior definitions an ABAP Repository Tree can be created. For that right click into your project explorer and select New > ABAP Repository Tree
Select “Applicant Component Hierarchy” and hit “Next”
Name the Tree “Application Component Hierarchy filtered by object type (EVTB)” and give the Property Filter “type:EVTB” and hit “Finish”.
The resulting tree displays all event bindings ordered by their respective domain. It can therefore be used to more easily find respective business events. The Business Partner Changed event can be found under “AP-MD-BP-RAP”.
When inspecting the event binding the behavior definition on which the event is defined can be found under “Entity Name”. In this case it is “I_BUSINESSPARTNERTP_2”
The event itself can also be found within the behavior definition.
Creating the CDS View for a derived event
As derived events are not triggered manually, a CDS view on the underlying business object of the event is required to fill it with data. Technically any CDS View on the underlying business object of a event can be used for a derived event without any modification as long as its respective keys match the keys of the business object. To demonstrate that we’ll create a small CDS View that can be used for the payload of the derived event.
Create a new package to contain all artifacts of the new derived events. Since the event “Business Partner Changed” is defined on “I_BUSINESSPARTNERTP_2” and it is not accessible through the released interface “I_BUSINESSPARTNERTP_3” (S/4HANA On Premise 2023), we’ll need to use the ABAP language version “Standard ABAP”. As such the software component “HOME” can be used for the package.
After creating the package create a new CDS View (data definition) within the package and select the fields “BusinessPartner”, “BusinessPartnerCategory” and “BusinessPartnerFullName” from the interface “I_BusinessPartner”. “I_BusinessPartner” is the underlying interface for the business partner business object and as such is also used by the behavior definition “I_BUSINESSPARTNERTP_2”.
@EndUserText.label: ‘Payload for BP Changed derived event’
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view entity Z_BP_CHANGED_PAYLOAD as select from I_BusinessPartner
{
key BusinessPartner,
BusinessPartnerCategory,
BusinessPartnerFullName
}
Defining the derived event
Derived events always need to be defined on the same behavior definition as the event it is deriving from. Since it is a very bad practice to edit standard artifacts of the S/4HANA system a behavior extension should be used on the behavior definition “I_BUSINESSPARTNERTP_2”. As such right click the behavior definition and select “New Behavior Extension” and create the extension.
Make sure that “I_BUSINESSPARTNERTP_2” is referenced as behavior definition.
Adjust the behavior extension to look as follows:
extension;
extend behavior for BusinessPartner
{
}
Next let’s add the definition for the derived event. The definition of a derived event follows the following template:
“managed event <derived event name> on <referenced event name> parameter <cds view>”
In case of the “Business Partner Changed” Event it should look like this:
extension;
extend behavior for BusinessPartner
{
managed event ChangedDerived on Changed parameter Z_BP_CHANGED_PAYLOAD;
}
Save and activate the behavior extension.
Publishing a derived event to AEM
Publishing a derived event is equal to publishing any other event. From a technical point of view a derived event is a completely independent event. As such a dedicated event binding has to be created and the respective topic bindings configured within the S/4HANA system. The exact process for that is described in the previous blogs.
To view all the events that have been send from the S/4 system over a communication channel use the transaction /IWXBE/EVENT_MONITOR. Select the channel you want to view and select “Outbound Events“. There you can view the events for the different topics.
This series of blogs intends to show in a step-by-step way the different possibilities to use RAP Business Events with Advanced Event Mesh. OverviewThe fourth blog of the RAP Business Events with Advanced Event Mesh series is gonna look at so called derived events. Derived events are events that are derived from other events and are always automatically triggered when that other event is triggered. While standard events can not be customised, derived events us CDS Views to determine the payload of a event. As such they are the ideal choice when the payload of a standard event is not sufficient. Derived events are however limited in their complexity as they only allow flat structures as payloads.In this blog we’ll be creating a derived event for the standard event “Business Partner Changed” and add two additional fields to its payload.Note: This blog focuses on S/4HANA On Premise 2023. With this release many events are only accessible through non-released interfaces. As such the ABAP language version “ABAP for Cloud Development” can not be used for the content of this blog. Finding RAP business event behavior definitionsBefore being able to create a derived event you’ll need to find the behavior definition where the standard event is defined. To make it easier to find these behavior definitions an ABAP Repository Tree can be created. For that right click into your project explorer and select New > ABAP Repository TreeSelect “Applicant Component Hierarchy” and hit “Next”Name the Tree “Application Component Hierarchy filtered by object type (EVTB)” and give the Property Filter “type:EVTB” and hit “Finish”.The resulting tree displays all event bindings ordered by their respective domain. It can therefore be used to more easily find respective business events. The Business Partner Changed event can be found under “AP-MD-BP-RAP”.When inspecting the event binding the behavior definition on which the event is defined can be found under “Entity Name”. In this case it is “I_BUSINESSPARTNERTP_2”The event itself can also be found within the behavior definition. Creating the CDS View for a derived eventAs derived events are not triggered manually, a CDS view on the underlying business object of the event is required to fill it with data. Technically any CDS View on the underlying business object of a event can be used for a derived event without any modification as long as its respective keys match the keys of the business object. To demonstrate that we’ll create a small CDS View that can be used for the payload of the derived event.Create a new package to contain all artifacts of the new derived events. Since the event “Business Partner Changed” is defined on “I_BUSINESSPARTNERTP_2” and it is not accessible through the released interface “I_BUSINESSPARTNERTP_3” (S/4HANA On Premise 2023), we’ll need to use the ABAP language version “Standard ABAP”. As such the software component “HOME” can be used for the package.After creating the package create a new CDS View (data definition) within the package and select the fields “BusinessPartner”, “BusinessPartnerCategory” and “BusinessPartnerFullName” from the interface “I_BusinessPartner”. “I_BusinessPartner” is the underlying interface for the business partner business object and as such is also used by the behavior definition “I_BUSINESSPARTNERTP_2”. @EndUserText.label: ‘Payload for BP Changed derived event’
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view entity Z_BP_CHANGED_PAYLOAD as select from I_BusinessPartner
{
key BusinessPartner,
BusinessPartnerCategory,
BusinessPartnerFullName
} Defining the derived eventDerived events always need to be defined on the same behavior definition as the event it is deriving from. Since it is a very bad practice to edit standard artifacts of the S/4HANA system a behavior extension should be used on the behavior definition “I_BUSINESSPARTNERTP_2”. As such right click the behavior definition and select “New Behavior Extension” and create the extension.Make sure that “I_BUSINESSPARTNERTP_2” is referenced as behavior definition.Adjust the behavior extension to look as follows: extension;
extend behavior for BusinessPartner
{
} Next let’s add the definition for the derived event. The definition of a derived event follows the following template:“managed event <derived event name> on <referenced event name> parameter <cds view>”In case of the “Business Partner Changed” Event it should look like this: extension;
extend behavior for BusinessPartner
{
managed event ChangedDerived on Changed parameter Z_BP_CHANGED_PAYLOAD;
} Save and activate the behavior extension. Publishing a derived event to AEMPublishing a derived event is equal to publishing any other event. From a technical point of view a derived event is a completely independent event. As such a dedicated event binding has to be created and the respective topic bindings configured within the S/4HANA system. The exact process for that is described in the previous blogs.To view all the events that have been send from the S/4 system over a communication channel use the transaction /IWXBE/EVENT_MONITOR. Select the channel you want to view and select “Outbound Events”. There you can view the events for the different topics. Read More Technology Blogs by SAP articles
#SAP
#SAPTechnologyblog