Maintain SAP-Events Header Fields.

Estimated read time 9 min read

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 like any other cloud events, 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:

From release 2023, 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 the 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

 Before commencing, you should bear in mind that only those events developed in an extendable cloud object can be maintained. To explore the feasibility, in your system and under Released Objects, EXTENDED_IN_CLOUD_DEVELOPMENT; look for the behavior definition of the event you are interested in

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:

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.  

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 here.
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 previous post
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.

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.

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.

The details of this process is nicely explained in this tutorial.

In the next blog post, I will explain to you how you can use an already implemented event with a different payload. So, stay put!

 

​ 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 like any other cloud events, 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:From release 2023, 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 the 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 Before commencing, you should bear in mind that only those events developed in an extendable cloud object can be maintained. To explore the feasibility, in your system and under Released Objects, EXTENDED_IN_CLOUD_DEVELOPMENT; look for the behavior definition of the event you are interested inIn 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: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.  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 attributePlease 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 here.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 previous post. 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.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.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.The details of this process is nicely explained in this tutorial.In the next blog post, I will explain to you how you can use an already implemented event with a different payload. So, stay put!   Read More Technology Blogs by SAP articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author