A constantly changing business landscape presents as many challenges as it does opportunities, not least of which is adapting to the latest technology trends. To help its customers take advantage of technological innovation, SAP has integrated a number of trends — such as in-memory technology, responsive user interface technology, and business networks — into its technology platforms. These trends have had a deep impact on the evolution and transformation of SAP technology, reflected by the development of the SAP HANA platform and the SAP Fiori user experience, and the addition of the Ariba, Fieldglass, and Concur solutions, for instance (see the sidebar "Major Recent SAP Technology Trends" for more on key trends and their influence on SAP technology).
There is now another trend taking hold that is transforming modern factories in a way that rivals the changes brought on by the invention of steam power and electricity: the Internet of Things (IoT). The ability of IoT-connected devices to talk to one another enables completely new “smart factory” scenarios, where machines and humans can collaborate in ways that were never before possible, such as robots assisting humans in complex manufacturing tasks. The production process in these smart factories represents a new evolutionary step called Industry 4.0.
SAP lays the foundation for its customers to take this next evolutionary step with support for IoT built into SAP HANA Cloud Platform. As of release 7.5, this support also extends to SAP NetWeaver Application Server (SAP NetWeaver AS) ABAP to support the integration of back-end processes, such as logistics and quality assurance processes, into Industry 4.0 scenarios. This article looks at how SAP NetWeaver AS ABAP supports Industry 4.0, and how to implement this support in your own SAP landscape.
SAP and Industry 4.0
Industry 4.0 makes it possible to integrate machines and sensors on the shop floor with IT systems along the entire value chain, even beyond a single enterprise. These connected systems can interact with one another using standard Internet-based protocols, such as the well-known Transmission Control Protocol (TCP), for faster, more flexible, and more efficient business processes, which fosters industrial growth and ultimately boosts the competitiveness of the enterprise. So how does SAP provide support for Industry 4.0 scenarios?
SAP HANA Cloud Platform supports the onboarding of IoT devices, such as temperature sensors, into an Industry 4.0 scenario in a simple and efficient way — you simply subscribe to a set of IoT services included with SAP HANA Cloud Platform and use an embedded cockpit tool to register devices and specify the supported message types for communicating data. Registered IoT devices then act as message senders and receivers for sending data to and from SAP HANA Cloud Platform.1
With SAP NetWeaver AS ABAP 7.5, it is now possible to establish a direct link between IoT devices and the on-premise ABAP stack, enabling you to integrate ABAP-based back-end processes into Industry 4.0 scenarios. For example, in a farming scenario you might want to track weather conditions to optimize the fertilizer ingredients, or in an assembly scenario you might want automated reports on the quality status of defective goods. Direct connection between the ABAP server and shop-floor devices eliminates the need for middleware components, simplifying the system landscape setup and lowering total cost of ownership.
SAP NetWeaver AS ABAP 7.5 enables this integration between shop-floor devices and back-end systems via a channel infrastructure that includes ABAP push channels (where the ABAP back end propagates a change to the front end) and ABAP messaging channels (where ABAP sessions exchange messages using a publish/subscribe model). Introduced with support package stack (SPS) 05 for SAP NetWeaver AS ABAP 7.4,2 the ABAP push channel and ABAP messaging channel infrastructure includes native support for the widely used TCP standard.
Let’s take a closer look at the technical details behind the infrastructure that enables IoT communication in the ABAP stack, and how the new ABAP channel programming model included with 7.5 simplifies application development.
Enabling an ABAP-Based Industry 4.0 Scenario
With SAP NetWeaver AS ABAP 7.5, the ABAP stack can play different roles in the TCP-based communication infrastructure for an Industry 4.0 scenario. It can play the role of a TCP client when the ABAP stack sends a message to an IoT-connected device that is acting as the server, or it can play the role of a TCP server when the ABAP stack receives a message from an IoT-connected device that is acting as the client. It can also interface with all existing standard protocols, such as the WebSocket Protocol and HTTP, allowing you to build almost any kind of web application or integration scenario.
Implementing an ABAP Program as the TCP Client
Let’s first look at how the ABAP stack connects as a TCP client to an existing TCP server via an ABAP message channel, enabling the ABAP stack to send messages to an IoT-connected device (to push an update to a device, for instance).
You can use any TCP server to do this. For demonstration purposes, we’ll emulate a very simple server using the ncat program (freely available from nmap.org). Start ncat from your system’s command line interface and let it listen for incoming requests from TCP clients. On the ABAP side, a simple report creates a TCP client object and connects to the designated TCP server by specifying the TCP server’s host IP address and port number.
The code to implement the TCP client, shown in Figure 1, looks a bit verbose but is fairly straightforward. In essence, it creates a TCP client object, connects to the TCP server (in this example, the ncat program) via a host and port, upon return composes a binary message from the input field terminated by the newline character, and sends it to the TCP server. Then the program waits for an incoming message from the TCP server via an ABAP push channel (ABAP command “WAIT FOR PUSH CHANNELS”), which is then displayed on the front end in an output list (ABAP command “WRITE”). The code is well documented inline, where you can read it or simply copy it to your ABAP editor — the Eclipse-based ABAP development tools for SAP NetWeaver (known as ABAP in Eclipse) or the ABAP Workbench (transaction SE80), for instance — and then compile and run it without any changes.
Let’s see what happens when we execute the report. First, in your ABAP editor (ABAP in Eclipse in the example), start the report with the standard report selection screen and specify the host IP address and port for the TCP server — for the example TCP server (the ncat program), this would be the local laptop or PC you are working with — along with a message to send to the TCP server (see Figure 2). In parallel, in the command line interface, start the ncat program listening on the specified host and port.
Now execute the report in the ABAP editor. A connection is established to the ncat program, which acts as the TCP server in this scenario, and the message is transferred to the ncat program, which echoes it to the command line interface (see Figure 3). You can then type in a line in the command line interface, which is sent back to the ABAP-based TCP client and written to the output list in the standard ABAP list screen (see Figure 4).
This simple scenario demonstrates the full bidirectional TCP communication channel 7.5 enables for any kind of message transfer from the ABAP stack to any outside device or process.
Implementing an ABAP Program as the TCP Server
Now let’s try it with the ncat program as the TCP client sending a message via an ABAP push channel to an ABAP program acting as the TCP server, an implementation approach that enables external IoT-connected devices and processes to send messages to the ABAP stack (so that sensors can communicate temperature changes, for example).
First, we create an ABAP push channel that acts as the TCP server endpoint. In ABAP in Eclipse — or alternatively in the ABAP Workbench — simply look for connectivity artifacts in the repository browser and select “ABAP push channels” from the navigation tree.
Then specify the name of the push channel and the usual change and transport properties. The system will create an SICF service (an Internet Communication Framework service) to enable HTTP communication and a corresponding ABAP push channel class based on the technical name.
The implementation of the ABAP push channel class (shown in Figure 5) is derived from an abstract base class named CL_APC_TCP_EXT_STATELESS_BASE. Note that you must implement the methods on_connection_setup, on_start, and most notably on_message, which is executed when a message arrives.
With the coding of the TCP server complete, you need to assign it to a port so that it can accept messages on that port from devices and processes that run outside of the ABAP stack. To do this, simply go to transaction SICF and create an external alias. Specify the external alias name and assign it to the service name generated earlier when creating the ABAP push channel (see Figure 6). Then use transaction SMICM to add a free port and associate the service URL so that the Internet Communication Manager can forward the TCP request to the appropriate handler class.
Now you can use the ncat program to connect to your TCP server and type in a message, which the ABAP-based TCP server then returns with the prefix “ON_MESSAGE has been successfully executed with text” that was specified in the implementation of the on_message method.
Another way to play around is to use the ABAP-based TCP client we created earlier and let it talk directly to the ABAP-based TCP server. In this case, start the report using the standard report selection as described previously with the hostname instead set to LOCALHOST, and the result from the ABAP-based TCP server is then written to the output list in the standard ABAP list screen.
An Example Industry 4.0 Scenario
Now that we have seen the basic mechanics of TCP client and TCP server code, let’s look at an example scenario where the ABAP stack serves as the TCP server (see Figure 7), receiving external communications, which is the more commonly used scenario.
Here, we use the ABAP-based TCP server to collect temperature values. These values are collected from external IoT-connected devices and processes by the ncat TCP client and sent to the TCP server. The TCP server then sends the values to an ABAP message channel, which forwards the values to an SAP Fiori-based chart control, created with SAPUI5 (SAP’s implementation of HTML5), that constantly redraws the temperature graph in the browser.
To enable this example scenario, we can reuse all of the artifacts discussed previously, such as the TCP server code. We must also create a new ABAP message channel in ABAP in Eclipse or in the ABAP Workbench, similar to the push channel that forwards the messages to the chart control, by adding handler code in the on_message implementation.
While in a real-life scenario the temperature graph would be updated with values sent automatically by sensors, you can add new entries manually through the ncat TCP client for demonstration purposes. When new values come in, the temperature graph is immediately updated via push notifications.
This is just a simple example, but it shows how easy it is to connect the ABAP channel infrastructure to the outside world with TCP communication.
IoT is changing the way businesses operate — particularly organizations in the manufacturing industry, which are undergoing significant transformation as the next industrial revolution moves forward. With increased connectivity and sophisticated analytics driving a new age of smart factories, and with the comprehensive back-end support for IoT communication built into SAP NetWeaver AS ABAP 7.5, SAP customers are poised not only to adapt to Industry 4.0, but to fully reap its rewards.
1 For more on how to securely register IoT devices with SAP HANA Cloud Platform, see Stefanie García Laule’s article “Ensuring a Secure Internet of Things” in the January-March 2016 issue of SAPinsider (SAPinsiderOnline.com). [back]
2 Learn more about the ABAP channels infrastructure in my article “A Foundation for the Future” in the July-September 2015 issue of SAPinsider (SAPinsiderOnline.com). [back]