ABAP Development, SAP S/4HANA

Integrating S4HANA and a model factory

Abstract

This blog post describes a student project in which a model factory was connected to a SAP S/4HANA system. The blog post describes how to connect an on-premise manufacturing execution system (MES) with a SAP S/4HANA instance running on the Google cloud platform. The focus of the blog post is on the required tools, how these tools are related to each other, as well as the necessary programming to achieve the outlined project goal.

Introduction

Furthermore, the integration should require a minimum of locally installed software besides the proprietary manufacturing execution system (MES) of the model factory. The goal of this integration was to send released production orders from the S/4HANA system to the MES of the model factory. An integration of the material stock or the confirmation of production activities was not part of this initial prototype. In this blog post I will describe the technical details of this integration. The overall system architecture is depicted in the following figure.

Read More: SAP S/4HANA Financial Accounting Certification

The left-hand side of the figure shows the on-premise system including the MES and the model factory. The goal is to connect to this system to a SAP S/4HANA hosted on Google Cloud platform. The S/4HANA system is shown on the right-hand side of the figure. The subsequent sections describe which software and tools were used to realize the described scenario. The remainder of the blog post is structured as follows:

1. Integration architecture

To integrate the on premise MES with the S/4HANA system running in the Google cloud platform the following software components were used:

  • Google Cloud Platform
  • SAP Cloud Platform
    • Destination (Service of CP)
    • WEB IDE (Service of CP)
  • SAP Cloud Appliance Library
    • SAP S/4HANA
  • SAP Cloud Connector

The following figure shows the relationship of the individual software components.

Architecture Overview

The bottom part of the right-hand side of the figure shows the SAP Cloud Appliance Library (SAP CAL). In the described project the SAP CAL was used to deploy a S/4HANA trail system into the Google cloud platform. In S/4HANA a BAdI was implemented to send data of released production orders to a predefined destination (using a HTTP Post). The central part of the figure shows the SAP cloud platform. Several services of the cloud platform are used in the architecture. The Web IDE is used to create a website to receive and forward our HTTP data to a destination in the SAP Cloud platform. The website basically acts as a proxy forwarding all incoming request to a defined destination. The service destination is the API of the MES running on premise. Using the SAP Cloud Connector the API of the MES system is made available in the SAP Cloud Platform. Finally, the MES running on premise receives the data send via HTTP and triggers the execution of the production process in the model factory.

To set up the S/4HANA system on the Google Cloud the following steps are necessary. Fortunately, there are already different blog posts available describing the required configuration steps.

1.1 Google Cloud Platform

Step1:

Let’s Set Up Google Cloud Platform
Necessary: 1.1; 1.2; 1.3; 1.4
(Getting access to the SAP CAL and the S/4HANA)

1.2 SAP Cloud Platform Cockpit

1.3 SAP Cloud Appliance Library

Step2:

Let’s Set Up SAP Cloud Appliance Library (CAL)
Create SAP NW ABAP 7.51 instance.

1.3.1 SAP S/4HANA

Step3:

Let’s Connect to Your Instance of SAP S/4HANA 1709 via SAP GUI
We only use 3a for this connection.
(Connecting to S/4HANA)

1.4 SAP Cloud Connector

After the previous steps it is now possible to connected to the SAP S/4HANA trail instance via the SAP GUI. The next step is the installation of the SAP Cloud Connector.

2. Establishment of the architecture

2.1 Cloud Connector – Exposing the MES to the SAP Cloud Platform

Now that all the required tools are ready, the next step is to expose the MES to the SAP Cloud Platform.

As data needs to be send from the SAP Cloud platform to the MES system via Cloud Connector a “Cloud To On-Premise” connection has to be configured.

A “Cloud To On-Premise” connection can be added in the SAP Cloud Connector in the following view Cloud To On-Premise > Access Control. Add a new system mapping using the +Icon.

In the following dialog the type of the back-end system needs to be selected. In our case the type is Non-SAP System.

In the next step we selected HTTP as the communication protocol.

We used the IP address and port of the MES system as the internal host and port.

Next, a virtual host and port can be defined. In this project we simply reused the IP and port of the MES system.

The principle type is set to None and an optional description is provided.

The result is the virtual system as shown in the following screenshot.

In order to enable access to the API of the MES system the accessible resources need to be configured. Using the +icon a new resource can be added.

In this project the URL Path was set to “/” and the access policy “Path and all sub-paths” was selected. This configuration enables access to all the APIs published by the MES system. Of course, in a productive scenario only the necessary resources of a back-end system should be published.

In the SAP Cloud Platform cockpit, the MES system is now shown as “available” in the Connectivity > Cloud connectors area.

2.2 Destination – Configuring a destination in the SAP Cloud Platform

In order to access the MES system in any service on the SAP Cloud Platform a destination needs to be created.

A destination created in the SAP Cloud Platform cockpit in the Connectivity > Destinations area. A new destination is added by click the “New Destination” icon.

This opens a dialog where a name is given to the destination and the URL of the MES system is configured. In this project the URL https://backend IP:backend port was used. Note, that the IP and port used here needs to be the virtual IP and port set during the configuration of the SAP Cloud Connector. The proxy type is set to “OnPremise” and “NoAuthentication” is chosen as the authentication method.

Please remember the Name you type in here, you will need it in the next step.

If everything is configured correctly, checking the destination should be successful.

2.3 WEB IDE – Creating the proxy Web Site

In order to expose the destination in the SAP Cloud Platform to the SAP S/4HANA running in the Google Cloud a proxy Web site is necessary. This website simply forwards all incoming requests to a defined destination. The SAP Web IDE can be used to build this Web site.

The SAP Web IDE is available in the Services section of the SAP Cloud platform. To access the SAP Web IDE for the first-time, type “Web” in the search bar in the “Services” section. Now the SAP Web IDE can be enabled, if necessary.

To access the SAP Web IDE klick on the SAP Web IDE Full-Stack.

In the Service overview of the SAP Web IDE click on “Go to Service” to get to the Web IDE.

The source code of the proxy web site is available here . The project can simply be imported into the Web IDE.

index.html

<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta charset="utf-8">
		<title>AWS SNS</title>
	</head>
	<body>
		<h1>AWS SNS</h1>
		<a href="/mes">Link</a>
	</body>
</html>

neo-app.json

{
	"welcomeFile": "/webapp/index.html",
	"authenticationMethod": "none",
	"routes": [{
		"path": "/",
		"target": {
			"type": "destination",
			"name": "mes",
			"entryPath": "/"
		},
		"description": "MES"
	}],
	"sendWelcomeFileRedirect": false
}

First you have to create a new folder in the SAP Web IDE workspace.

Then the downloaded zip-file can be imported by clicking on File > Import > File or Project select the file and your just created folder. The result is a webapp folder with an index.html and a neo-app.json file.

If you now open neo-app.json you should see something like in the following picture.

If anything isn’t as shown here please change it like this excluding the section “name”. To forward incoming http request to the destination configured in the SAP Cloud Platform, type in the name of your destination set in the previous step.

Finally, the proxy Web site needs to be deployed on to the SAP Cloud platform. Once this is done, the set-up of the integration infrastructure is complete. Any HTTP request to the proxy Web site should now be routed to the MES.

2.3 BAdI – Sending released production orders to the MES

The final step is to implement a Business Add-In (BAdI) in the S/4HANA system. This BAdI (WORKORDER_UPDATE [Operation: UPDATE]) is responsible for sending the data of released production orders to the MES system via the proxy Web site.

The prototype for the BAdI implementation code:

CLASS zcl_s4_mf_wo_update_impl DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES if_badi_interface .
    INTERFACES if_ex_workorder_update .
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS ZCL_S4_MF_WO_UPDATE_IMPL IMPLEMENTATION.


  METHOD if_ex_workorder_update~archive_objects.

  ENDMETHOD.


  METHOD if_ex_workorder_update~at_deletion_from_database.

  ENDMETHOD.


  METHOD if_ex_workorder_update~at_release.
    DATA: http_client TYPE REF TO if_http_client,
          payload_x   TYPE xstring.

    DATA(order_id) = CONV i( is_header_dialog-aufnr ).

    DATA(quantity) = CONV i( is_header_dialog-bmenge ).

    DATA(material_id) = 111.

    "Material mapping
    IF is_header_dialog-matnr = |MZ-FG-C900|.
      material_id = 222.
    ENDIF.

    DATA(payload)  = | \{ "order_id":{ order_id }, "material_id":{ material_id }, "total_quantity":{ quantity } \} |.

    cl_http_client=>create_by_destination(
      EXPORTING
        destination              = 'MES_CD'    " logical Destination (at the beginning of function)
      IMPORTING
        client                   = http_client ).    " HTTP Client abstraction

    http_client->request->set_method('POST').
    http_client->request->set_content_type( 'application/json' ).


    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        text   = payload
      IMPORTING
        buffer = payload_x.

    http_client->request->set_data( payload_x ).

    http_client->send(
      EXCEPTIONS
        http_communication_failure = 1
        http_invalid_state         = 2
        http_processing_failed     = 3
        http_invalid_timeout       = 4
        OTHERS                     = 5 ).

    IF sy-subrc = 0.
      http_client->receive(
        EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state         = 2
          http_processing_failed     = 3
          OTHERS                     = 5 ).
    ENDIF.

    IF sy-subrc <> 0.
      "error handling
    ENDIF.
  ENDMETHOD.


  METHOD if_ex_workorder_update~at_save.

  ENDMETHOD.


  METHOD if_ex_workorder_update~before_update.

  ENDMETHOD.


  METHOD if_ex_workorder_update~cmts_check.

  ENDMETHOD.


  METHOD if_ex_workorder_update~initialize.

  ENDMETHOD.


  METHOD if_ex_workorder_update~in_update.

  ENDMETHOD.


  METHOD if_ex_workorder_update~number_switch.

  ENDMETHOD.

In the BAdI implementation a logical system destination is used. This destination needs to be configured in transaction SM59 and point to the URL of the proxy Web site.

Once the BAdI is implemented and activated any release of a production order results in sending this production order to the MES using the described integration architecture.

Leave a Reply

Your email address will not be published. Required fields are marked *