Skip to Content
Technical Articles
Author's profile photo Benedikt Sprung

Custom Events in SAP Event Mesh. Step-by-Step (Part 1 – Create a Custom Event)

Overview

In this step-by-step guide, we will cover the following:

  • How to create a Subtype of a Business Object
  • How to create Events for the Business Object
  • How to establish the Event Linkage for Change Documents
  • Finally, how we can make use of it in our SAP NetWeaver add-on for event enablement

 

Part 1: We will create a custom Event Linkage for a Material Change using transaction SWO1 and SWEC.

Part 2: Now we can make use of it in our SAP NetWeaver add-on for event enablement.

 

Introduction to Part 1

This becomes necessary when the Business Object does not offer the desired event that we want to trigger. A typical example is the change of a material where the “Change Event” is not available by default. Hence, we will proceed with the creation of a subtype that includes the Change Event using the following four steps.

 

Step 1: Find your Business Object

In our case, we aim to trigger a Material Change, which corresponds to the Business Object BUS1001.

Go to transaction SWO1–> “Business Object Repository”.

Figure%200%20Navigation%20to%20the%20Business%20Object%20Repository

Figure 1 Navigate to the Business Object Repository

There you will find the Business Object under:

Logistics – General –> Logistics Basic Data –> Material Master –> BUS1001

Double-click on BUS1001 to view the default available events.

As we can see there is no Change Event available by default.

Figure%202%20Find%20BUS1001%20in%20SWO1

Figure 2 Check the events of BUS1001 in SWO1

 

Step 2: Create a subtype of BUS1001

Go to Transaction SWO1 and create a subtype of BUS1001. Maintain the details as illustrated in the accompanying figure.

Figure%202%20Creating%20a%20subtype%20in%20transaction%20SWO1

Figure 3 Creating a subtype in transaction SWO1

 

Step 3: Create a Change Event

  1. Click on the “Change” button to review the newly created ZBUS1001 Object. It is now a copy of BUS1001, and we will add our change event here.
  2. Select and mark “Events” and then click on the “Create” button.
  3. A popup will appear for your new Material Change Event. Maintain the necessary details in the popup.

Figure%203%20Create%20your%20new%20Event

Figure 4 Create your new Event

 

Figure%204%20Now%20your%20subtype%20of%20BUS1001%20should%20look%20like%20this

Figure 5 Now your subtype of BUS1001 should look like this

 

Place your cursor on the event and release it:

Edit -> Change Release Status -> Object Type -> To implemented.
Edit -> Change Release Status -> Object Type Component -> To implemented.

Finally, click on the generate button.

Figure%205%20Release%20it%20and%20generate%20it%20afterward

Figure 6 Release it and generate it afterwards

 

Step 4: Event Linkage for Change Documents

Now that we have created our new ZBUS1001 Object Type, the next step is to link it to a change event in the system.

Go to transaction SWEC New Entries.

Add your Object Type that you just generated in the previous step and click on the save button.

Note: We can utilize the Function Module /ASADEV/ACI_CPIDENT_TRANSFER to provide the key of the change document and pass it to the SAP NetWeaver add-on for event enablement. This allows for its usage in data extraction.

Figure%206%20Create%20the%20linkage%20between%20event%20and%20subtype

Figure 7 Create the Event Linkage for Change Documents

 

Optional Step 5: Field Restrictions

By following the first four steps mentioned above, we have successfully created an Event that will be triggered whenever a change is made to a material.

However, there are cases when we do not want to receive notifications for every single change made to a material. In such cases, we can utilize Field Restrictions to specify the specific events we want to monitor.

This is also done in Transaction SWEC. Choose the Object Type that we created in Step 4 and click on Field Restrictions. In this example, we are only interested in being notified when a Material Group is changed or when the Material is locked. We will exclude notifications for any other changes made to a material. By implementing these restrictions, we will only receive notifications for the defined events, ensuring we are not overwhelmed by irrelevant notifications.

Figure%2007%20Field%20Restrictions%20in%20SWEC

Figure 8 Field Restrictions in SWEC

Conclusion

We have successfully extended a subtype of the Business Object BUS1001 by incorporating a material change through the following actions:

  • Create subtype BO in SWO1
  • Create an event for our subtype in SWO1
  • Linked a change document to the BO event in SWEC

Now that we have completed these steps, we are ready to utilize the SAP NetWeaver add-on for event enablement.

In Part 2 we will ocus on capturing a Material Change and seamlessly transmitting it in real-time to the cloud.

Please provide feedback or thoughts in the comment section.
There is a Q&A regarding the SAP Event Mesh.
You can also follow the tags and profiles for more upcoming articles.

Assigned Tags

      11 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Rajesh Chiplunkar
      Rajesh Chiplunkar

      Thanks for sharing the post. We were able successfully configure a custom event using the clear instructions provided by you. We observed that field restrictions work for the fields which are captured in the change log. However, as per our requirement we want to restrict the event creation only for a specific set of documents i.e. sales documents of a particular order type or Sales org.

      We tried to configure the same by giving old and new field values of sales org. as same. However, the change log does not capture these values unless there is a real change and hence are trigger fails.

      Can you please provide feedback on how we can achieve this ?

      Thanks in advance.

      Author's profile photo Martin Schöffler
      Martin Schöffler

      Hi Rajesh,

      you can also do filtering using a check FM in the event linkage. There you can write checks in custom ABAP logic to decide if the event should be fired or not.

      There is also a pre-delivered one in the framework: /ASADEV/ACI_EVENTS_CHECK

      It checks against filter values that are defined as header attributes on the outbound objects in the following notation:

      BOR_ATTRIBUTE_<attribute_name>

      Where <attribute_name> is the name of an attribute of the Business Object. As value you give the value that restricts the event.

      Kind regards,

      Martin

      Author's profile photo kuldeep tiwari
      kuldeep tiwari

      Hello Benedikt,

      We have created custom change event for material master in S4 HANA and it is working as expected.

      Whenever the field restriction is applied on that event, hence the event does not emit.

      Although, our requirement is specific that the event needs to be triggered for material group A002 from S4 system.

      Kindly suggest the steps to attain the event.

      Thanks,
      Kuldeep
      Author's profile photo Benedikt Sprung
      Benedikt Sprung
      Blog Post Author

      Hello Kuldeep,

      with the field restrictions you are using the event will only be triggered when the MATKL changes from A001 to A002.

      If you only want to trigger materials for MATKL A002 you could use a User Exit or a BAdI, check the MATKL and CALL FUNCTION 'SWE_EVENT_CREATE' if it's A002.

      Kind regards

      Benedikt

      Author's profile photo Per Åge Themte
      Per Åge Themte

      Hi,

      Are the ASADEV/ package generally available in any S/4 system or does it require payed addons?

      Author's profile photo Benedikt Sprung
      Benedikt Sprung
      Blog Post Author

      Hi,

      to be able to download the add-on you need an active subscription of the Enterprise Messaging service. The Add-on component is available at the Software Center.

      Author's profile photo Per Åge Themte
      Per Åge Themte

      Benedikt Sprung Hi!,

      I've just installed the add-on to our new S/4 instance and followed a few blogs. I managed to get the event to fire when using BO BUS2032 (sales order), but using a subtype of either 2032 og 1001 does not do anything. I've followed the guide above with the same data, but no events can be found in the monitor. Can you please provide some useful hints on how to troubleshoot this? Are the release status on the new event important? Cause your guide tells me to component to released, but the type to implemented. When trying that, SAP complaints that the lower level component can have an higher status than the type. I did release both, but still no event was triggered (empty field restrictions..)

      Please advice 🙂

      Author's profile photo Benedikt Sprung
      Benedikt Sprung
      Blog Post Author

      Hi,

      great to hear that you have succesfully configurated your first events.

      Did you exchange the subtype with the standard bo type in the "Event Linkage"?

      To troubleshoot it, you can check in transaction SWEL if the event is visible there. (activate it with transaction SWELS).

      Another way to simulate the event is in transaction SWUE. Use your subtype there.

      Kind regards,

      Benedikt

      Author's profile photo Per Åge Themte
      Per Åge Themte

      Well, I added it. But do I need to replace it for the provided one for material?

      Author's profile photo Benedikt Sprung
      Benedikt Sprung
      Blog Post Author

      Yes you can replace it. Your ZBUS1001 also contains the events from BUS1001.

      Author's profile photo Marta De la Sota
      Marta De la Sota

      Good morning.

      I need to add a field in SWEC but it isn't possible select it because it doesn't exist in the list. This field is LIKP-BOLNR. How could I add this field? I know it is possible to add a field because in my system there are Z fields.

       

       

      Thanks a lot.

      Marta.