How We Built a Logistics App Leveraging SAP Leonardo in Less Than 10 Days

SAP Blog Post

At SAP TechEd Las Vegas, Bjorn Goerke, Chief Technology Officer and President of SAP Cloud Platform at SAP, boldly went where no enterprise has gone before. During his Star Trek-themed keynote, he announced the Mendix & SAP partnership. The SAP Cloud Platform Rapid Application Development by Mendix brings together two best-of-breed technologies to provide unrivaled experience to customers. During the keynote, Jana Richter, Head of Product Management for SAP Cloud Platform Core, presented two applications built using the Mendix Platform. But how did we build these applications? What services did we use? In this blog post, we will uncover what it took to build the connected logistics app.

Choosing a suitable use case

Weeks before the launch of the Mendix and SAP partnership, the Evangelist team was tasked with building a demonstration application. This application needed to showcase the latest technology that both companies offer.

We decided to reuse a previous use-case involving tracking the transportation of goods, covered in this blog post. One of the most critical issues when transporting goods is the correct storage and transportation. While in transit, there are many factors that can adversely affect cargo, such as exposure to light, temperature increases and decreases, movement, and humidity. Ensuring the correct conditions are continually met while many different handlers and carriers are involved across the global supply chain can be challenging.

We wanted to enhance this demo using data and services provided by SAP. SAP is used by 87 percent of the Forbes Global 2000 companies, making it almost an essential part of every large enterprise.

When deciding the services and data we would want to use from SAP, we identified four key technologies to use:

  • Blockchain
  • IoT
  • S/4HANA
  • SAP Cloud Platform.

At SAP Sapphire, SAP announced their new suite of IoT, machine learning and blockchain technologies, under the brand SAP Leonardo. SAP Leonardo brings new technologies and services together to help businesses power their digital transformation.

We wanted to leverage these services and supplement them with data from other SAP systems. When tracking the transportation of goods, it is important to know which orders the goods belong to. To get this data, we needed to integrate into our S/4 HANA system to pull sales orders. To host and scale to our application, we chose the SAP Cloud Platform using the native integration provided in the Mendix platform.

Using SAP Leonardo IoT

To track the condition of our cargo, the containers are fitted with sensors. These sensors continuously send out lots of data, which needs to be analyzed and recorded. The SAP Leonardo IoT platform allows you to manage multiple devices and sensors, allowing these sensors to send data to the IoT platform. This data is then securely stored, allowing your applications to read and analyze this data. Working with the SAP teams, we set up an IoT service using SAP Leonardo IoT V4, the latest IoT platform announced at SAP Sapphire. Using the API and Web Interface, we set up several devices and device certificates to allow us to securely connect to the service.

SAP Leonardo IoT Example Screenshot

Connecting to the SAP IoT service is either done using REST or MQTT protocols. We decided to use the MQTT, a lightweight protocol used primarily in the IoT space because it would allow us to both publish and receive data using one connection. By using modules from the Mendix App Store, we were easily able to build the integration into the SAP Leonardo IoT platform. We used the MQTT connector module, which enables Mendix apps to both subscribe and publish to MQTT topics. In our scenario, we wanted to subscribe to the MQTT topics published from SAP.

To make demoing the app easier and demonstrate MQTT publishing, we built a simulator into the application. The simulator allows us to send temperature, humidity, movement and light data to the IoT service and visualize this on our display. The simulator will send data to the service every second. When the service receives data, it is stored in SAP where Mendix can then receive the data via MQTT subscribe. Alternatively, you can retrieve this data via REST. Every time a message is received, a microflow is executed with topic information and a message payload in JSON format. To import the data, we set up a mapping between the JSON data and the Mendix domain model.

SAP IoT Example Screenshot

Using Blockchain

Before the transportation of goods, organizations will often compile lengthy contracts agreeing how the goods should be transported and the penalties if this contract is broken. During transportation, incidents often occur that can affect the condition and value of goods. Often these events will break the agreed contract. However, it is often difficult to identify how this contract was broken, when and by whom. This is where Blockchain technology in combination with Smart Contracts make an ideal solution.

Smart Contracts are self-executing agreements based on blockchain technology, which triggers actions once a condition has been met. For instance, when we report a temperature that is too high, we want to record this, store it against the order contract and alert the customer.

Blockchain is an ideal technology for these types of scenarios because it gives us an immutable ledger of all events. This ledger cannot be changed or tampered with, making it suitable to ensure there is no way to dispute events. Blockchain technology has applications in all sorts of areas, including logistics, healthcare, banking, and much more.

SAP, like their IoT platform, provides a service that makes it easy to set up a blockchain. The SAP blockchain is based on the Hyperledger Fabric open source platform. Hyperledger, unlike other blockchain technologies, does not run a Cryptocurrency. Hyperledger blockchains run chaincodes, programs written usually in GoLang. Developers can create their own code functions to interact with the blockchain.

We created our own chaincode using GoLang, which looks like this:

Blockchain Code Screenshot

The code contains three functions that allow the user of the chaincode to write, read, and search the chain.

Once the chaincode is written, we need to run it on the SAP Blockchain Service.

Blockchain Example Screenshot

The SAP Blockchain service comes with some out of the box REST APIs to help interact with the chaincode. The API has two operations: Invoke and Query. Invoke is used to call a chaincode function and Query for getting the chaincode’s state.

To interact with these APIs we used the native REST capabilities in Mendix to build a microflow to add a block to our chain, find a block in our chain, and find all blocks for an order. To use the API, you need to create an API Key which can be created in the SAP service cockpit.

Microflow Screenshot

Microflow Example Screenshot

SAP S/4HANA

When adverse events occur, such as increased temperature, we need to know which orders will be affected. Having a complete trail of all sales orders and purchase orders is imperative to understand the business impact. SAP S/4HANA is a real-time enterprise resource management suite in the cloud. The service comes with several out-of-the-box OData services, making it easy to receive and submit data. As part of the SAP launch, Mendix has launched many SAP connectors into various SAP technologies such as S/4HANA, SuccessFactors, Leonardo, and Ariba. These connectors can be found in the Mendix App Store and are free to download. For this application, we used the S/4Hana connector to add and view purchase orders from our S/4 system.

SAP S/4HANA Example Screenshot

SAP Cloud Platform

To demonstrate the Logistics app, we needed somewhere to host our application. We decided to use the recently released Mendix integration into SAP Cloud Platform. The SAP Cloud Platform is an open source Platform as a Service (PaaS) which provides unique in-memory database and business application services. The platform utilizes Cloud Foundry technology to deliver an open, robust, and flexible multi-cloud architecture. The Mendix product seamlessly integrates into the SAP Cloud Platform and handles all communication and updates via our cloud portal. Mendix handles the creation of all the required services, including a database service and single-sign-on service.

To start using the SAP Cloud Platform, you can choose an SAP-enabled starter template via the “Create App” button on the Mendix Buzz portal. Some of the templates are based on Fiori design and others based on the Mendix Atlas framework. Once you have chosen a template, the platform will ask you to authenticate with the SAP Cloud Platform. Once authenticated, you can select the region, organization, and space you wish to deploy to.

SAP Cloud Platform Screenshot

Once you have set up an environment, you can simply hit the run button in the Desktop Modeler and the app will stage and deploy into the SAP Cloud Platform. Deploying an existing application to the SAP Cloud Platform can be done by using the cloud settings under the general settings for your project. Customers now have the option to deploy to the Mendix Cloud, SAP Cloud or On Premises from the Mendix portal, making it easier to switch between different cloud environments. Once the project is connected to the desired environment, you can simply press the “Run” button in the Modeler to deploy your application.

SAP Cloud Platform Example Screenshot

When the application is deployed in the SAP Cloud Platform, users can configure and bind additional SAP services. Services, such as blockchain, HANA, audit logs and object stores, can easily be added and bound to extend an application.

The Final Product

The final solution demonstrates the power of combining Mendix and SAP, and how two leaders in their spaces can work together to help enterprises boldly go where they have never gone before. We built the app at unprecedented speed using out-of-the-box connectors to SAP.

Now what will you build?

Download the SAP Solutions Brief