Remotes for SAP

Introduction and architecture

The Perfion “Remotes” feature allows Perfion to display or store data from sources like SQL, OData or web services.

This page describes an example configuration of a Perfion remote which accesses data from SAP.

The SAP setup described in the document is not the only possible way to achieve the result. SAP is a complex and flexible solution, so depending on the system landscape of the individual customer, a different way of exposing the data to Perfion could be more suited.

This example demonstrates one possible configuration, utilizing SAP Cloud Platform Integration (CPI) to expose a web service. The CPI is connected to an on-prem SAP ERP system using the SAP Cloud Connector. Hence the prerequisites for this solution is a CPI tenant, the SAP Cloud Connector and an SAP ERP System.

The example web service exposes material data, which are fetched by the Perfion remote and shown alongside other data features in the Perfion application.

 

The SAP Cloud Connector connects the two systems by setting up a secure tunnel.

SAP Setup

SAP ERP

To expose the material data, a remote enabled function module has been programmed named Z_GET_MATERIALS. The source code of the function module can be seen in appendix I. The function module is a simple wrapper function module that first uses the standard BAPI BAPI_MATERIAL_GETLIST. This BAPI takes a selection structure (see appendix II) and returns a table with the material numbers that match the material selection. For each of these material numbers, the other standard BAPI BAPI_MATERIAL_GET_DETAIL is called. This BAPI returns the material data for material number it is given. These material data along with the material number is inserted into a Z-structure (see appendix III) and returned as the response of the call of Z_GET_MATERIALS.

SAP Cloud Connector

In order to make the remote function module accessible for the CPI, we use the SAP Cloud Connector. The SAP Cloud Connector connects the on-prem (on premise) ERP system to a SAP Cloud account/tenant.

The picture below details this principal:

For more details on installing the SAP Cloud Connector we refer to this blog:
How to guide - Connectivity Setup with ABAP and SAP Cloud Connector

When the SAP Cloud Connector is installed, the following function modules BAPI_MATERIAL_AVAILABILITY, BAPI_TRANSACTION_COMMIT, BAPI_TRANSACTION_ROLLBACK and Z_GET_MATERIALS need to be assigned as accessible from the “Cloud to On-Prem” tab:

SAP Cloud Platform Integration

The integration flow made in the CPI is quite straight-forward. Since the CPI is message agnostic, it can be made like this:

As shown above, the Integration Flow receives a SOAP request from a caller. This request is forwarded unaltered to the ERP On-Prem system via RFC. This RFC destination:

Is maintained in the Cloud Cockpit of the CPI tenant:

It is important to assign the additional properties.

Perfion Configuration

In order to get live SAP data to Perfion we will use a web service type remote. This type of remote requires a web service with a special Perfion interface to be implemented. The details about the Perfion web service interface can be found in the Perfion Remotes manual.

The concept is shown in the image below. One has to create a new Perfion web service, which consumes SAP web services and serves Perfion with data based on what type of data Perfion expects to get in various different scenarios. It would also be possible to modify the actual SAP web service directly to fulfill the Perfion requirements, but in this example we retain the extra “wrapper” layer to keep the SAP web service simple.

Several examples of different scenarios how data can be used in Perfion:

  • Perfion grid

  • Perfion item editor

  • Import

  • Reports

  • Etc.

For example, if data is used in Perfion grid, then Perfion will send a request to Perfion web service with remote data keys (for example it could be SAP material numbers) and then it expects to get data back from it including extra data related to those keys (e.g. any other data exposed for each material by SAP web service). Perfion web service purpose, in this case, is to send a request to SAP web service with the same keys to get more detailed information about requested data, process the data by removing unwanted data or modifying results in the way they have to be used in Perfion and return results back to Perfion. It is not a requirement that Perfion web service should use another web service to get the data. The data source can be anything, e.g. database, file, FTP, etc.

Perfion web service is simple and flexible, so the implementation complexity depends on user requirements. Moreover, Perfion web service can be used to serve many remotes in Perfion. For example, one can create a remote which will use product price as its data, while the other remote will use the number of available products. Both parameters can be retrieved using the same SAP web service request, but then in Perfion web service the data must be processed and returned to Perfion based on which remote feature asked for the data.

Perfion Remote Web Service

Perfion web service must have only one web method “GetData”, which accepts query (XML format) as an input and returns a C# DataSet with a single DataTable serialized as XML. Both input and output have to meet some requirements which are described in detail in the Perfion Remotes manual. Below is shown how Perfion web service endpoint look:

Below is a pseudo-code, which shows how to process data in a Perfion web service. The code is executed when one calls “simulator.SelectRemoteData(query)”. It uses query (queryXml) input, which is received from Perfion, processes data and returns a serialized DataSet back to Perfion.

Remote Query

Before it is possible to create a new remote feature in Perfion, a new remote query must be created. A remote query can be compared to a database query and connection string to database.

The new remote query can be created by opening remote queries from Perfion main menu by choosing Administration -> Remote Queries. Then in the new window one can press Ctrl+N. The detailed procedure is described in Perfion Remotes manual.

In Remote Query window one has to specify the connection string to Perfion web service and to add remote query configuration.

The image below shows how to specify connection to Perfion web service.

The image below shows remote query which can retrieve data from Perfion remote web service. The table with data at the bottom of remote query window is the actual data example retrieved from the Perfion web service by executing a test.

Please refer to Perfion Remotes manual for detail instructions how to specify remote query.

Key Feature and Remote Feature

The next step is to create a remote feature, which will use the new remote query.

Remote feature cannot be used alone, it needs a key feature, which was also defined in remote query – SapTestKey. This feature will keep the keys of remote data. In our example it will be SAP material numbers.

A new feature can be create from Features pane in Perfion.

Finally, one can create a remote feature. The remote feature in Perfion from configuration point of view differs from a normal feature only by having two extra fields which can be defined in “Remote” section. If those fields are filled, then feature becomes a remote feature in Perfion.

Two images below shows definitions for both new features.

Field “Group” in the images above is an information group in Perfion and each feature must have it. Groups can be defined from Administration -> Information Groups -> Groups (tab). In our example it is called “Remotes”, but it can be any other group.

Remote feature from our example will use material description as its data, therefore for RemoteDescription feature we select remote query created in the previous step (SAP_RemoteWsSingle) as “Query” and “Description” as “Data Field” value. Since our example Perfion web service returns several columns with data, any of those columns can be selected as a data field for remote feature. One can also create other remote features which would use different data field values.

In our example Perfion web service returns Description, Type, Width, Height, Created and LastModified columns.

Example

In the following we will show an example of how the material data is displayed in the SAP ERP system, the data in the service and how it is shown in the Perfion application.

We are using the material “ITM002” as an example. In the SAP ERP System the basic data for the material can been seen via the transaction code MM02:

To get the material data with the service the following request is used:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:rfc:functions">    <soapenv:Header/>    <soapenv:Body>       <urn:Z_GET_MATERIALS>          <MATNRSELECION>             <item>                <SIGN>I</SIGN>                <OPTION>CP</OPTION>                <MATNR_LOW>ITM002</MATNR_LOW>                <MATNR_HIGH></MATNR_HIGH>             </item>          </MATNRSELECION>       </urn:Z_GET_MATERIALS>    </soapenv:Body></soapenv:Envelope>

This returns the following response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">    <soap:Header/>    <soap:Body>       <rfc:Z_GET_MATERIALS2.Response xmlns:rfc="urn:sap-com:document:sap:rfc:functions">          <MATERIAL_DATA>             <item>                <MATERIAL>ITM002</MATERIAL>                <MATL_DESC>it.mobile Material w/o batch, w/SUM</MATL_DESC>                <OLD_MAT_NO/>                <MATL_TYPE>FERT</MATL_TYPE>                <IND_SECTOR>M</IND_SECTOR>                <DIVISION/>                <MATL_GROUP>01</MATL_GROUP>                <PROD_HIER/>                <BASIC_MATL/>                <STD_DESCR/>                <LAB_DESIGN/>                <PROD_MEMO/>                <PAGEFORMAT/>                <CONTAINER/>                <STOR_CONDS>01</STOR_CONDS>                <TEMP_CONDS/>                <BASE_UOM>ST</BASE_UOM>                <EAN_UPC>3000000000403</EAN_UPC>                <EAN_CAT>HE</EAN_CAT>                <SIZE_DIM/>                <GROSS_WT>1.500</GROSS_WT>                <NET_WEIGHT>1.000</NET_WEIGHT>                <UNIT_OF_WT>KG</UNIT_OF_WT>                <VOLUME>10.000</VOLUME>                <VOLUMEUNIT>M3</VOLUMEUNIT>                <LENGTH>0.000</LENGTH>                <WIDTH>0.000</WIDTH>                <HEIGHT>0.000</HEIGHT>                <UNIT_DIM/>                <MANU_MAT/>                <MFR_NO/>                <BASE_UOM_ISO>PCE</BASE_UOM_ISO>                <UNIT_OF_WT_ISO>KGM</UNIT_OF_WT_ISO>                <VOLUMEUNIT_ISO>MTQ</VOLUMEUNIT_ISO>                <UNIT_DIM_ISO/>                <CREATED_ON>2015-07-10</CREATED_ON>                <CREATED_BY>SFJ</CREATED_BY>                <LAST_CHNGE>2019-01-02</LAST_CHNGE>                <CHANGED_BY>OSL</CHANGED_BY>                <MATL_CAT/>                <EMPTIESBOM/>                <BASIC_MATL_NEW/>             </item>          </MATERIAL_DATA>          <MATNRSELECION>             <item>                <SIGN>I</SIGN>                <OPTION>CP</OPTION>                <MATNR_LOW>ITM002</MATNR_LOW>                <MATNR_HIGH/>             </item>          </MATNRSELECION>       </rfc:Z_GET_MATERIALS2.Response>    </soap:Body></soap:Envelope>

In Perfion the data can be used in many places. Below is an example, where data is displayed in Perfion grid.

The data fields shown in light blue color are remote feature data fields. The feature SapTestKey defines the remote data key and remote feature RemoteDescription retrieves its data from SAP service in real time by using remote data key defined in SapTestKey feature. In this example we have also another remote feature in the grid – RemoteType.

Another example is “Product 1” item shown in the “Item Editor” window:

Appendix I – Source code of Z_GET_MATERIALS

FUNCTION Z_GET_MATERIALS.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      MATNRSELECION STRUCTURE  BAPIMATRAM
*"      MATERIAL_DATA STRUCTURE  ZBAPIMATDOA
*"----------------------------------------------------------------------

DATA MATNRS TYPE STANDARD TABLE OF BAPIMATLST INITIAL SIZE 0.
DATA iMaterials TYPE STANDARD TABLE OF BAPIMATDOA INITIAL SIZE 0.

CALL FUNCTION 'BAPI_MATERIAL_GETLIST'
EXPORTING
  MAXROWS                            = 200
 TABLES
   MATNRSELECTION                     = MATNRSELECION

*MATERIALSHORTDESCSEL               =

*MANUFACTURERPARTNUMB               =

*PLANTSELECTION                     =

*STORAGELOCATIONSELECT              =

*SALESORGANISATIONSELECTION         =

*DISTRIBUTIONCHANNELSELECTION       =

  MATNRLIST                          = MATNRS

*RETURN                             =

          .
Data wa_matnr type BAPIMATLST.
loop at matnrs into wa_matnr.
  data mat_details type BAPIMATDOA.
  data zmat_details type ZBAPIMATDOA.

  CALL FUNCTION 'BAPI_MATERIAL_GET_DETAIL'
    EXPORTING
      MATERIAL                    = wa_matnr-MATERIAL

*PLANT                       =

*VALUATIONAREA               =

*VALUATIONTYPE               =

*MATERIAL_EVG                =

   IMPORTING
     MATERIAL_GENERAL_DATA       = mat_details

*RETURN                      =

*MATERIALPLANTDATA           =

*MATERIALVALUATIONDATA       =

            .
  MOVE-CORRESPONDING mat_details to  zmat_details.
  zmat_details-material = wa_matnr-MATERIAL.
  Append zmat_details to MATERIAL_DATA.
endloop.
ENDFUNCTION

Appendix II – Structure

Field

Name

Typing

Method

Field

Type

Data

Type

Length

Decimals

Description

SIGN

Types

BAPISIGN

CHAR

1

0

Inclusion/exclusion criterion SIGN for range tables

OPTION

Types

BAPIOPTION

CHAR

2

0

Selection operator OPTION for range tables

MATNR_LOW

Types

MATNR_V

CHAR

18

0

From material number

MATNR_HIGH

Types

MATNR_B

CHAR

18

0

To material number