In this blog post, I show you how you can do source side filtering of events in SAP BTP ABAP environment, what Dynamic Topics are and how we can use them for routing and filtering of events in SAP Integration Suite advanced Event Mesh.
Here, I represent two different ways of filtering of RAP business events in SAP BTP ABAP environment. On the left-hand side, you can see the SAP BTP ABAP environment system that produces some RAP business events. These events are then sent as CloudEvents to the right-hand side, to the Advanced Event Mesh instance.
In the first Part, we discuss Source Side Filtering of events which is available from release 2402 in SAP S/4HANA Cloud and SAP BTP ABAP environment and in SAP S/4HANA and SAP S/4HANA Cloud, Private Edition since release 2023 SP00. For a RAP business event, then you can define filterable properties from the actual payload of that event. This means, if there’s a field called for example “country code”, you can make it filterable by exposing it as CloudEvents context attribute. Then you can define filter conditions as well, like the country code must match the amount US or DE. If this filter condition is not met, then the event is not sent out of the system. If you want to prevent some events to go out due to the data privacy protection issues or reduce traffic due to unnecessary events, then you can use event filtering.
In the second part, we discuss Dynamic Topic Filtering and routing of events with the integration with the Advanced Event Mesh. As a further remark, this feature is available from release 2408 in SAP S/4HANA Cloud, Public Edition and SAP BTP ABAP environment and in SAP S/4HANA and SAP S/4HANA Cloud, Private Edition since release 2023 SP02.
Source side filtering of RAP business events
Assume you are in your BTP ABAP environment system, and you have a RAP business event. This RAP business event has a corresponding abstract entity where you define your actual payload. Let’s say you have a payload that contains a field “country code”:
This is a payload of a RAP business event without predefined filters. In the data part, the country code has the value DE and in the upper part you can see the header fields of the CloudEvent.
You want to know how you can make this property filterable? quite easy! As you define the event, you need to add the annotation “@Event.context.attribute” before the field you want to use as a filter and then give it a name like “xsapcountrycode” for example:
.context. attribute:’xsapcountrycode’
CountryCode: abap.char(2);
Then, during the runtime, the country code value “DE” is exposed inside the Cloud Event Context as an additional attribute with the name you have defined as the value of the annotation explained above:
With that the payload field ‘Country Code’ becomes a new filter attribute. the source side filtering is available for every event infrastructure that we curreHowever, there are some restrictions which must be considered, for example not all properties are allowed for exposing in header, e.g., amount fields or cf. annotation, more information can be found in
Maintain Filters for Outbound Event Topics | SAP Help PortalEvent Annotations | SAP Help Portal.
This SAP Note describes in more detail what must be considered when creating filters and which restrictions apply.
The next step would be going to filter configuration UI and there you can select all the filterable fields like xsapcountrycode and define filter conditions like ‘eq ‘DE’ ’. You can also define filters containing multiple fields and add additional filter conditions for those fields.
Let’s look at the runtime, for example if you have an event with country code “DE”, this would be published because it would match the filter condition we already defined. Whereas if you have an event with country code “US”, this does not match the filter condition and would therefore be filtered out. This means if you want to prevent events from going out, for example due to data privacy protection or any other reason, then you can define corresponding filter conditions.
Define source side filters in your application
I already build a very simple application, an online shop as it is described in this tutorial. I added the field country code as well to use it later as a filter, so when I create a new item, I can assign a country code for the country I want to ship the item to.
Now, we want to make sure that only events created for items that are shipped to “DE” are also published to the event exchange infrastructure . I create the event that should be raised whenever an item is created and the parameter or the fields that should be in this event are defined in this abstract entity and it looks like this:
@EndUserText.label: ‘Event parameter’
define abstract entity ZD_ItemOrdered_0000 {
ItemName : abap.char(25);
@Event.context. attribute:’xsapcountrycode’
CountryCode: abap.char(2);
}
To make this event filterable, I just add this simple annotation “@Event.context.attribute” and I call it xsapcountrycode. when I activate this entity, for all events that are raised inthis system, the field “CountryCode” is propagated into the Cloud Event context and contains the values that is in the payload. As a next step, we must define the filter criteria for the given event channel as well.
After creating your communication arrangement, go to “Configure Channel Binding” application to configure the related channel and add your outbound topic which is created during event binding creation as is explained in the tutorial. As you see, there is no event filters defined yet. Keep in mind that you can only add filters to existing outbound bindings.
You can see here we have an outbound topic which is the event from the application. Now I want to define the filter. You can create filters on each topic individually by clicking on it. Then in event filter tab, click on ‘create’ and choose the filter property. By clicking on “Create” the filter will be generated successfully. All defined filters are displayed under Event Filter Expression.
We can head back to the channel and see that there is event filters configured:
Now let’s try to see if the filter works properly. For that, we will use our event monitor application which is a tool where you can monitor the status of your in/outbound events. First, you can see there are no events on this channel, we want to change that now.
I go into my Fiori application and press “create” to create an order, a laptop for example, and I want to send that to Germany (DE). If you remember, this will match our filter criteria and therefore it would be sent out. An event can be monitored as expected, in the launchpad open the application “Enterprise Event Enablement-Event Monitor”, you can see an event reach your channel:
If we look at the payload, we see the country code “DE” in the header as well
Now to check if this filter works, I want to create another object in here, let’s say I want to ship a tablet to Spain. I create this order and head back to our Event Monitor application. You can see the number of events hasn’t changed, so the event with country code “ES” did not match our filter criteria and therefore was filtered. Note that you cannot monitor or log events that are filtered out. Such event behaves as if the event was never raised!
Dynamic topic filtering in Advanced Event Mesh
Dynamic topics enable detailed event filtering and routing, ensuring that events are delivered only to the relevant components, improving efficiency and reducing unnecessary processing The feature of Dynamic Topics is only available for channels integratingwith the Advanced Event Mesh (AEM) . For more information regarding AEM, please follow Get Started with SAP Integration Suite, Advanced Event Mesh.
agine you have your RAP business event in BTP ABAP environment system, with the same abstract entity, that represents the actual event payload with the country code field. Similarly, you must add an additional annotation to enable Dynamic Topic or to enable that the country code is added as an additional segment to the Dynamic Topic. The first part of the annotation is the same; we have the event context attribute and then we give it a name, and additionally you also need to define a position. This is because you could have multiple Dynamic Topic segments, and we need to know at which position each one should be put, so you can order them in the way you need them.
.context:{attribute:’xsapcountrycode’,position: 1}
CountryCode: abap.char(2);
As you see below, the country code is exposed to the header part, but the difference is, you can see at the end of the standard topic the value of the country code field is added as well. Since you could define multiple properties, the position is so important to be added to the Dynamic Topic because we need to know at which position after the standard topic, the Dynamic Topic segment for the given property should be added
Besides, we want to use this field for routing and filtering the events in Advanced Event Mesh and for that, you also need to know the exact location of the specific property you want to use as a filter.
This is already everything you must do in BTP ABAP environment for your Rap business event. . Assume you want to have two filters, one for the country code “DE” and the other one for the country code “US”. For that, you must define two queues in your Advanced Event Mesh.
Let’s say for example in the “US” queue you only want to have events of the country code “US”. Then, you define this topic subscription accordingly and you need to do the same thing for the second queue where you want to receive the events with the country code “DE”.
Now I will show you how to route your events in practice. I have reverted all the changes I’ve made to enable source side filtering, so there is no event filters defined. Now we want to send out all the events and then put them into different queues depending on their properties. As it is explained before this is how our abstract entity must look like
@EndUserText.label: ‘Event parameter’
define abstract entity ZD_ItemOrdered_0000 {
ItemName : abap.char(25);
@Event.context:{attribute:’xsapcountrycode’,position: 1}
CountryCode: abap.char(2);
}
Create a channel for the integration with AEM, either by using the SAP GUI transaction in S/4HANA or SAP S/4HANA Cloud, Private Edition or respective communication arrangements in SAP S/4HANA Cloud , Public Edition or SAP BTP ABAP Environment (as described Get Started with SAP Integration Suite, Advanced Event Mesh). You can enable Dynamic Topics by using the button “Enable Dynamic Topics” which is only enabled for Advanced Event Mesh channels. By clicking on this button and enabling the Dynamic Topics, you can see that something has changed, namely the topic now contains this Dynamic Topic segment “xsapcountrycode”:
Now I go to the connected Advanced Event Mesh broker and configure two queues, one for country code “DE” and another one for “US”:
In subscriptions section of “DE” queue for example, you can see the topic we have for “DE” country code
and for the “US” it’s comparable. That’s everything that needs to be done to route events.
Let’s create a new order to be shipped to “US”. Then in our event monitor app, there is an event here and you can see also the outbound event tab has changed to signify this topic schema, so you know there are Dynamic Topics in place.
If we look at this event, we can see the Dynamic Topic segment is indeed “US” and if we check the payload, it’s the same as before, we have our xsapcountrycode which is lifted to the header and the country code in there:
Now let’s look at our queues and you can see one message has reached the US queue:
With that, you have a simple but powerful routing tool for your events.
Summary
Here I shortly presented the newly developed possibilities of event filtering and routing for SAP ABAP Cloud. Source side filtering prevents events from being published based on the filters we define using the payload fields which are exposed to the Cloud Eventn context. This can be used to satisfy data privacy and protection restrictions or also in case you wanted to distribute the load among different connections. By means of the Dynamic Topic feature we are now able to route and filter the events in Advanced Event Mesh broker. Both features are already available in the current SAP S/4HANA Cloud, Public Edition, SAP S/4HANA, SAP S/4 HANA Cloud Private Edition as well as SAP BTP ABAP environment releases.
In the near future, the customer should also able to choose any valid payload fields of the given RAP event type as an event filter attribute without using annotation “@Event.context.attribute”. Please follow the community page to get informed regarding updates in Enterprise Event Enablement content.
In this blog post, I show you how you can do source side filtering of events in SAP BTP ABAP environment, what Dynamic Topics are and how we can use them for routing and filtering of events in SAP Integration Suite advanced Event Mesh.Here, I represent two different ways of filtering of RAP business events in SAP BTP ABAP environment. On the left-hand side, you can see the SAP BTP ABAP environment system that produces some RAP business events. These events are then sent as CloudEvents to the right-hand side, to the Advanced Event Mesh instance.In the first Part, we discuss Source Side Filtering of events which is available from release 2402 in SAP S/4HANA Cloud and SAP BTP ABAP environment and in SAP S/4HANA and SAP S/4HANA Cloud, Private Edition since release 2023 SP00. For a RAP business event, then you can define filterable properties from the actual payload of that event. This means, if there’s a field called for example “country code”, you can make it filterable by exposing it as CloudEvents context attribute. Then you can define filter conditions as well, like the country code must match the amount US or DE. If this filter condition is not met, then the event is not sent out of the system. If you want to prevent some events to go out due to the data privacy protection issues or reduce traffic due to unnecessary events, then you can use event filtering. In the second part, we discuss Dynamic Topic Filtering and routing of events with the integration with the Advanced Event Mesh. As a further remark, this feature is available from release 2408 in SAP S/4HANA Cloud, Public Edition and SAP BTP ABAP environment and in SAP S/4HANA and SAP S/4HANA Cloud, Private Edition since release 2023 SP02.Source side filtering of RAP business eventsAssume you are in your BTP ABAP environment system, and you have a RAP business event. This RAP business event has a corresponding abstract entity where you define your actual payload. Let’s say you have a payload that contains a field “country code”:This is a payload of a RAP business event without predefined filters. In the data part, the country code has the value DE and in the upper part you can see the header fields of the CloudEvent.You want to know how you can make this property filterable? quite easy! As you define the event, you need to add the annotation “@Event.context.attribute” before the field you want to use as a filter and then give it a name like “xsapcountrycode” for example:.context. attribute:’xsapcountrycode’
CountryCode: abap.char(2);Then, during the runtime, the country code value “DE” is exposed inside the Cloud Event Context as an additional attribute with the name you have defined as the value of the annotation explained above:With that the payload field ‘Country Code’ becomes a new filter attribute. the source side filtering is available for every event infrastructure that we curreHowever, there are some restrictions which must be considered, for example not all properties are allowed for exposing in header, e.g., amount fields or cf. annotation, more information can be found in Maintain Filters for Outbound Event Topics | SAP Help PortalEvent Annotations | SAP Help Portal. This SAP Note describes in more detail what must be considered when creating filters and which restrictions apply.The next step would be going to filter configuration UI and there you can select all the filterable fields like xsapcountrycode and define filter conditions like ‘eq ‘DE’ ’. You can also define filters containing multiple fields and add additional filter conditions for those fields. Let’s look at the runtime, for example if you have an event with country code “DE”, this would be published because it would match the filter condition we already defined. Whereas if you have an event with country code “US”, this does not match the filter condition and would therefore be filtered out. This means if you want to prevent events from going out, for example due to data privacy protection or any other reason, then you can define corresponding filter conditions.Define source side filters in your application I already build a very simple application, an online shop as it is described in this tutorial. I added the field country code as well to use it later as a filter, so when I create a new item, I can assign a country code for the country I want to ship the item to. Now, we want to make sure that only events created for items that are shipped to “DE” are also published to the event exchange infrastructure . I create the event that should be raised whenever an item is created and the parameter or the fields that should be in this event are defined in this abstract entity and it looks like this:@EndUserText.label: ‘Event parameter’
define abstract entity ZD_ItemOrdered_0000 {
ItemName : abap.char(25);
@Event.context. attribute:’xsapcountrycode’
CountryCode: abap.char(2);
}To make this event filterable, I just add this simple annotation “@Event.context.attribute” and I call it xsapcountrycode. when I activate this entity, for all events that are raised inthis system, the field “CountryCode” is propagated into the Cloud Event context and contains the values that is in the payload. As a next step, we must define the filter criteria for the given event channel as well. After creating your communication arrangement, go to “Configure Channel Binding” application to configure the related channel and add your outbound topic which is created during event binding creation as is explained in the tutorial. As you see, there is no event filters defined yet. Keep in mind that you can only add filters to existing outbound bindings.You can see here we have an outbound topic which is the event from the application. Now I want to define the filter. You can create filters on each topic individually by clicking on it. Then in event filter tab, click on ‘create’ and choose the filter property. By clicking on “Create” the filter will be generated successfully. All defined filters are displayed under Event Filter Expression.We can head back to the channel and see that there is event filters configured:Now let’s try to see if the filter works properly. For that, we will use our event monitor application which is a tool where you can monitor the status of your in/outbound events. First, you can see there are no events on this channel, we want to change that now. I go into my Fiori application and press “create” to create an order, a laptop for example, and I want to send that to Germany (DE). If you remember, this will match our filter criteria and therefore it would be sent out. An event can be monitored as expected, in the launchpad open the application “Enterprise Event Enablement-Event Monitor”, you can see an event reach your channel:If we look at the payload, we see the country code “DE” in the header as wellNow to check if this filter works, I want to create another object in here, let’s say I want to ship a tablet to Spain. I create this order and head back to our Event Monitor application. You can see the number of events hasn’t changed, so the event with country code “ES” did not match our filter criteria and therefore was filtered. Note that you cannot monitor or log events that are filtered out. Such event behaves as if the event was never raised!Dynamic topic filtering in Advanced Event MeshDynamic topics enable detailed event filtering and routing, ensuring that events are delivered only to the relevant components, improving efficiency and reducing unnecessary processing The feature of Dynamic Topics is only available for channels integratingwith the Advanced Event Mesh (AEM) . For more information regarding AEM, please follow Get Started with SAP Integration Suite, Advanced Event Mesh.agine you have your RAP business event in BTP ABAP environment system, with the same abstract entity, that represents the actual event payload with the country code field. Similarly, you must add an additional annotation to enable Dynamic Topic or to enable that the country code is added as an additional segment to the Dynamic Topic. The first part of the annotation is the same; we have the event context attribute and then we give it a name, and additionally you also need to define a position. This is because you could have multiple Dynamic Topic segments, and we need to know at which position each one should be put, so you can order them in the way you need them..context:{attribute:’xsapcountrycode’,position: 1}
CountryCode: abap.char(2);As you see below, the country code is exposed to the header part, but the difference is, you can see at the end of the standard topic the value of the country code field is added as well. Since you could define multiple properties, the position is so important to be added to the Dynamic Topic because we need to know at which position after the standard topic, the Dynamic Topic segment for the given property should be addedBesides, we want to use this field for routing and filtering the events in Advanced Event Mesh and for that, you also need to know the exact location of the specific property you want to use as a filter.This is already everything you must do in BTP ABAP environment for your Rap business event. . Assume you want to have two filters, one for the country code “DE” and the other one for the country code “US”. For that, you must define two queues in your Advanced Event Mesh.Let’s say for example in the “US” queue you only want to have events of the country code “US”. Then, you define this topic subscription accordingly and you need to do the same thing for the second queue where you want to receive the events with the country code “DE”.Now I will show you how to route your events in practice. I have reverted all the changes I’ve made to enable source side filtering, so there is no event filters defined. Now we want to send out all the events and then put them into different queues depending on their properties. As it is explained before this is how our abstract entity must look like@EndUserText.label: ‘Event parameter’
define abstract entity ZD_ItemOrdered_0000 {
ItemName : abap.char(25);
@Event.context:{attribute:’xsapcountrycode’,position: 1}
CountryCode: abap.char(2);
}Create a channel for the integration with AEM, either by using the SAP GUI transaction in S/4HANA or SAP S/4HANA Cloud, Private Edition or respective communication arrangements in SAP S/4HANA Cloud , Public Edition or SAP BTP ABAP Environment (as described Get Started with SAP Integration Suite, Advanced Event Mesh). You can enable Dynamic Topics by using the button “Enable Dynamic Topics” which is only enabled for Advanced Event Mesh channels. By clicking on this button and enabling the Dynamic Topics, you can see that something has changed, namely the topic now contains this Dynamic Topic segment “xsapcountrycode”:Now I go to the connected Advanced Event Mesh broker and configure two queues, one for country code “DE” and another one for “US”:In subscriptions section of “DE” queue for example, you can see the topic we have for “DE” country codeand for the “US” it’s comparable. That’s everything that needs to be done to route events. Let’s create a new order to be shipped to “US”. Then in our event monitor app, there is an event here and you can see also the outbound event tab has changed to signify this topic schema, so you know there are Dynamic Topics in place.If we look at this event, we can see the Dynamic Topic segment is indeed “US” and if we check the payload, it’s the same as before, we have our xsapcountrycode which is lifted to the header and the country code in there:Now let’s look at our queues and you can see one message has reached the US queue:With that, you have a simple but powerful routing tool for your events.SummaryHere I shortly presented the newly developed possibilities of event filtering and routing for SAP ABAP Cloud. Source side filtering prevents events from being published based on the filters we define using the payload fields which are exposed to the Cloud Eventn context. This can be used to satisfy data privacy and protection restrictions or also in case you wanted to distribute the load among different connections. By means of the Dynamic Topic feature we are now able to route and filter the events in Advanced Event Mesh broker. Both features are already available in the current SAP S/4HANA Cloud, Public Edition, SAP S/4HANA, SAP S/4 HANA Cloud Private Edition as well as SAP BTP ABAP environment releases.In the near future, the customer should also able to choose any valid payload fields of the given RAP event type as an event filter attribute without using annotation “@Event.context.attribute”. Please follow the community page to get informed regarding updates in Enterprise Event Enablement content. Read More Technology Blogs by SAP articles
#SAP
#SAPTechnologyblog