Technology Blog Posts by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Enterprise Event Enablement provides the opportunity of developing event driven applications either by producing RAP business events or consuming events. Now, assume that based on a business requirement you would like to filter the SAP events according to some event fields of the body. Hence, it is needed to make these fields visible by adding them to the header fields.  Subsequently, I show you how it is done and what the requirements are.

SAP Business Accelerator Hub provides wide list of SAP S/4HANA Cloud Event Objects. By choosing a certain event object and its event references, you can see that each SAP event has a payload which carries detailed information of the event packet, known as a body, and a distinct header that describe what the event is. For example, looking at the event references of the creation of a sales order event we have:

filter1.png

From S/4HANA 2023 release for private and public cloud as well as on premise, attributes defined in the 'DATA' section of a business event or in other words, the body of the event, can be promoted to the header to become Custom Extension Context Attributes of the Cloud Event Context. As it’s known, the body contains the actual data being exchanged, and for security reason and unlike header data, it is not visible to the outside world. For example, imagine that based on a business requirement you would like to filter this type of event according to some event fields of the body. Hence, it is needed to make these fields visible by adding them to the header fields. Alternatively, the header attributes can also be used for source side filtering in the publisher system, either by the customer or an event middleware like Event Hub. Hereafter, I show you how easy you can expand header fields!

Add Data Fields to the Header of a Payload

first of all, in your S/4 HANA development system, open the ABAP Development Object, as it shown below, and look for the SAP Object type, in our case ‘SALESORDER.’ Then in the ‘Relation Explorer’ you can find all the related objects to this object type. Here we need to know how the Behavior Definition is called.

customev2.jpg

 Bear in mind that only those events developed in an extendable cloud object can be maintained. To explore the feasibility, we need to check whether the Behavior Definition we are interested in, namely R_SALESORDERTP, is extensible.
To begin with, create the Released Objects view on the repository of your system in your ADT Project. You can create it using New->ABAP Repository Tree context menu on your ADT project with the Property Filter “api: extend_in_cloud_development”:

de12.jpg

Knowing the name of the Behavior Definition and under Released Objects, EXTENDED_IN_CLOUD_DEVELOPMENT; look for this Behavior Definition. 

filter2.png

In the relevant Behavior Definition find the related event parameter, in which the event is defined, for example in our case and for the event 'SalesOrderCreated', open the behavior definition ‘R_SALESORDERTP’ and check the related parameter for this event:

filter3.png

It is important that the abstract entity ‘D_SalesOrderCreated’ has the annotation showing that metadata extension is allowed, otherwise we are not able to extend that event.  

filter4.png

Now that our entity is extendable, create your own ABAP project, and by right clicking on your package, add new metadata extension for this entity as follows:

 

@Metadata.layer: #CORE
annotate entity D_SalesOrderCreated
  with 
{
@Event.context.attribute: 'xsapsotypesgb'
    SalesOrderType;
}

 

Beware that per event, i.e. parameter, only one meta data extension can be created. The main requirement is to add the annotation '@Event.context.attribute' for the respective field of a RAP entity which is used to define the business event type. There is also a naming convention for the attributes which are supposed to be promoted from the 'DATA' section of the event type into the Cloud Event Context as follows:

<extensionAttributeName>:=xsap<name>
  <name>:= name of the extension attribute

Please keep in mind that the XSAP prefix should be reserved for SAP delivered header attributes, but currently it is also mandatory for custom attributes. Besides, the type of system of the Cloud Event Context is more restrictive than the type of system of the event 'DATA' section. It means, only the following data types: Boolean, Integer, String, Binary, URI, and Timestamp are allowed. Hence, attributes which have been promoted from the 'DATA' section of the event type into the Cloud Event Context will be converted to the type 'String’ if their original data type is not allowed for the Cloud Event Context. More restriction can be found in SAP help page about Event Annotations .
Now, we save and activate the meta data extension, and change to the FLP to create a communication arrangement for the event enablement scenario (if we don’t have any) and maintain the channel as it is explained in my blog post How to Create RAP Business Events
Then, we need to configure the outbound channel. After selecting your channel in ‘Enterprise Event Enablement’ application, click on ‘create’ and find the topic related to the selected SAP event. In our case, sales order created.

filter5.png

Now whenever a new sales order is created, an event will be raised, and you can see your modified header. For this, open the application ‘Enterprise Event Enablement-Event Monitor’, choose your channel, and open the related payload of the published event.

filter6.png

As you can see, the chosen attribute with the given name is shown in the header part. Now, you can use this attribute as a filter for the corresponding event type. In the Outbound Topics table, the column ‘Has Event Filters’ indicates whether filters are defined for the outbound topic. Go back to the Enterprise Event Enablement ‒ Configure Channel Binding app, choose your channel and select your outbound topic binding. To add a filter to the outbound topic, choose ‘Create Event Filter’. Under property, you can either choose your own defined property, in our case ‘xsapsotypessgb’, or use the standard context attributes.

filter7.png

The details of this process are nicely explained in this tutorial Maintain Filters for Outbound Event Topics.

In the next blog post, I explain How one can Create a New event from an SAP Standard Event.

6 Comments
Labels in this area