Connect to SAP S/4HANA system to consume OData services through OData Connector

Background introduction

Today's fierce global market competition requires companies to innovate quickly and respond to complex business changes in order to achieve differentiation. As a strategic partner of SAP, Mendix can help SAP users quickly expand core applications such as S/4HANA, improve the efficiency of enterprise-level application development, and greatly save resource input. This article takes S/4HANA as an example to introduce how to connect to a locally deployed SAP system and consume OData services through the OData Connector provided by Mendix.

Prerequisites and precautions

  1. S/4HANA locally deployed system and corresponding login information
  2. Install Mendix Studio Pro, version recommendation: 8.0.0-8.17.99
  3. The application has been created in Menidx Studio Pro
  4. OData Model Creator for SAP solutions can help import the Data Model that has been built in the SAP system into the Mendix project. The official document has the prerequisite requirements and tips as shown in the following figure for the use of OData Model Creator for SAP Solutions:

Combined with the actual situation of use, here are two tips:

[Prompt 1]: In order to successfully import the generated Module into Mendix Studio Pro, please follow the second suggestion above and install the version of Mendix Studio Pro 8.0.0-8.17.99 to avoid import errors;

[Tip 2]: OData Model Creator for SAP solutions  only supports SAP OData Gateway Services of OData version 2 and 3. OData 4 does not currently support it.

S/4HANA system released OData  Service

The OData service consumed in this article is the SAP Gateway OData service published for self-built data tables in the S/4HANA system. Since SAP self-development is not the focus of this article, only a brief description is given here. For detailed development process, please refer to relevant SAP documents.

  1. Transaction code SE11, create sales order header table, line item table
  2. Transaction code SEGW-SAP Gateway Service Builder defines the project and associates the data model to implement the CRUD method
  3. Transaction code /IWFND/MAINT_SERVICE-Activate and Maintain Services to register SAPGateway OData service, for example, here is: ZSO_CRUD_SRV
  4. Transaction code /IWFND/GW_CLIENT-SAP Gateway Client test the OData service built
  5. View OData service metadata : View the metadata of the defined OData service in the browser 

http://<hostname>:50000/sap/opu/odata/sap/ZSO_CRUD_SRV/$metadata , right click to download the metadata and save it in the file $metadata.xml for subsequent import to Mendix.

Get the Data  Model defined in SAP

OData Model Creator for SAP solutions generates data models that can be used in Mendix based on the metadata of the SAP system. The generated module can subsequently be imported into Mendix Studio Pro and used in the connection scenario with the SAP system.

1. Enter Mendix-SAP OData Service Wizard (mendixcloud.com) through the link below .

2. Select the Manual method, upload the metadata XML file downloaded previously, and click Continue to generate the Schema.

3. Select the generated Schema ZSO_CRUD_SRV, and click Continue.

4. View and generate a Data Model file that can be imported into Mendix.

Click the button "Generate.mpk" and download and generate the ZSO_CRUD_TEST_SRV.mpk file. It is recommended to save the file in the resources directory of the project (for example: "~\Documents\Mendix\SAPLaunchpad-main\resources") for later use.

For specific steps, please refer to the official Mendix document: https://docs.mendix.com/partners/sap/use-sap-odata-model-creator .

 

Use the OData Connector for SAP Solutions module in Mendix  Studio Pro

1. Download the OData  Connector  for  SAP  Solution component

OData Connector for SAP Solution is an extended component of Mendix and needs to be downloaded from the APP Store provided by Mendix.                                                                 

Enter Mendix Studio Pro and click the icon in the upper right corner , directly search for the keyword "OData" or find the component "OData Connector for SAP solutions" in Categories->Connectors->SAP. 

Click to enter the download page.

Click the "Download/Download" button, and the corresponding components will be downloaded to Mendix Studio Pro and placed under the directory APP Store modules: 

2. Import the generated SAP  Data  Model module file

Import the SAP Data Model module file ZSO_CRUD_TEST_SRV.mpk generated in the fourth part into the project.

Right-click in the project root directory -> select "Import module package".

Select the file in the previously stored directory and import it.

Choose to add as a new module when importing.

The imported module will be displayed at the bottom of the project root directory, as shown in the following figure:

You can double-click "Domain Model" to view the data model defined in the SAP system; double-click EntitySetNames to view the corresponding OData entity; the constant ZSO_CRUD_SRV stores the URL to access this OData service:

3. Use OData  Connector in APP

Create a username and password to connect to the SAP system

Right-click MyFirstModule -> Add other -> Constant to add a constant, and add the user name and password as follows.

Create micro flow to get sales order information

Right-click MyFirstModule->Add microflow..., here named DS_GetSOHeaders, used to consume OData service to get the sales order header information and fill it in the sales order page for display. Create the microflow as follows:

(1)Create request params

(2)Add basic authentication

Maintain the Request parameters, username and password.

(3)Get List

Response type – ZSO_CRUD_SRV.Header

Destination – empty

Query – @ZSO_CRUD_SRV.ZSO_CRUD_SRV + '/' + toString(ZSO_CRUD_SRV.EntitySetNames.HeaderSet)

(The Query parameter here is actually the spliced ​​HTTP Request. The request after splicing is: http://vhcals4hci.dummy.nodomain:50000/sap/opu/odata/sap/ZSO_CRUD_SRV/HeaderSet )

Request parameters – $SAPRequestParams

Parent – empty

Result info – empty

Use return value – Yes

List name – ListofHeader

(4) Return to ListofHeader at the end of the microflow

The final microflow defined is as follows:

Create a sales order display page and associate the above microflow

Create a new page, select the layout of the master-slave structure, and associate the data source with the microflow just created.

Adjust the layout, the main information of the order header table is listed on the left, such as: order number, description, and detailed information is displayed on the right after selection. After compilation and running, the display results are as follows: 

to sum up

The connector function OData Connector for SAP solutions provided by Mendix helps seamlessly integrate with the SAP system, thereby consuming the OData services defined in the SAP system, so that the expansion and development of the SAP system can be easily expanded outside the core application, which reduces the solution At the same time of complexity, it reduces the impact that SAP system upgrades may face in the future.

For more detailed information about the implementation of this article, you can also refer to the official document:

https://docs.mendix.com/partners/sap/use-sap-odata-connector

https://docs.mendix.com/partners/sap/sap-odata-connector 

 

thanks for reading!

 

 

 

Guess you like

Origin blog.csdn.net/Mendix/article/details/113859195