Supply Chain Management Blogs by SAP
Expand your SAP SCM knowledge and stay informed about supply chain management technology and solutions with blog posts by SAP. Follow and stay connected.
Showing results for 
Search instead for 
Did you mean: 


This blog post will guide you through the steps to create a connection between a SAP S/4 HANA system and SAP Leonardo IoT using Integration Flows (IFlows). SAP Leonardo Internet of Things(IoT) simplifies execution of Stock Replenishment by configuring Rules and Actions. Rules can be configured so as to take action in SAP Leonardo IoT, for example if Fill level is less than 30%, send email notifications and create Purchase Requisitions.This integration is elaborated in following steps.


  1. Once device is modelled in SAP Leonardo IoT, various containers which are used to store materials can be maintained along with their properties.



  1. Create a rule.

In SAP Leonardo IoT cockpit, first Rule context needs to be created and then Rule can be created using that context.

Once Rule Context is defined, Rule can be created. For instance, when Fill Level is less than 30, this Rule should get triggered.

  1. Integration Flow(IFlow) is created to create purchase order in SAP S/4 HANA Test system(QE6). Following two OData services are used.

    1. Get request to fetch X-CSRF token.

    2. Post request (using this X-CSRF token), which creates order in QE6 system


Post Request block used in IFlow is as follows.


Groovy Script

Once CSRF token is fetched in Get request, below code sets it in the Header for Post request.


def Message processData(Message message)


def headers = message.getHeaders();

def cookie = headers.get("Set-Cookie");

StringBuffer bufferedCookie = new StringBuffer();

for (Object item : cookie)


bufferedCookie.append(item + "; ");


message.setHeader("Cookie", bufferedCookie.toString());

def messageLog = messageLogFactory.getMessageLog(message);

if(messageLog != null)


messageLog.setStringProperty("Logging_Cookie", bufferedCookie.toString());


return message;


This IFlow is then deployed to get the URL which can be configured in Actions. (Step 5 and 6)

  1. Cloud connector is set up between QE6 system and D0408 Cloud Platform Integration (CPI) client.

  1. This IFlow Url is then set as destination.

  1. Next, Actions are configured to be executed on triggering of Rules. Following two actions are configured.

1. FillLevelStreamingEmail Action

Email should be generated to the Email Ids in Recipients List with the text that is                              configured in Action. Subject can also be configured.

2. PRCreation Action

On trigger of Rule, that is as soon as Fill level reaches below 30, Purchase requisition                        should get created in QE6 system.

Sample payload is given and Destination that was set in Step 5 is used for this.

  1. Schedule rule

Rules can be scheduled to run every minute or hour as follows.

  1. Once Rule is triggered, both the actions get executed.

Subject for email can be checked, that it is for the Container whose fill level was below 30%, and when it was below a threshold value recipients are notified.

In QE6 system, following Purchase Requisitions get created.

  1. Rules and Action Simulator

Rules and Action Simulator is provided in SAP Leonardo IoT Cockpit for testing. In first screen, data can be ingested for a device(thing), say 8 Tons for Container 500.

Once data is ingested, next screen is Rule Selection. On selecting rule from dropdown, actions related to the rule gets listed below which would be executed on trigger of the Rule.

Hence, depending on Fill Level of containers, PR is created in SAP S/4 HANA system and email notification is sent.


Hence, by configuring rules and actions in SAP Leonardo IoT, integration with SAP S/4 HANA system can be easily achieved.