Monday 31 December 2018

Use SAP Cloud Connector + SAP Cloud Platform + Java to consume function in ABAP On-Premise system

Recently I was assigned to a prototype development which needs to consume some function modules in ABAP On-Premise system.

SAP Cloud for Customer is a cloud solution whose OData service / Web Service could directly be consumed by other application in the Internet. And the prototype I am working on recently needs to consume function modules in ABAP On-Premise system hosted in Corporate Network, which is not directly available for Internet application.

To bridge this gap, SAP Cloud Connector is used.

In this blog I implement a simple scenario to demonstrate how Cloud Connector works: develop a Java Web application which consumes function module in ABAP On-Premise system, and deploy it onto SAP Cloud Platform. I can access this Java application via Wechat application in my mobile phone, and then function module in ABAP system is called.

Major implementation steps:

1. Download and configure Cloud Connector, which should be deployed in Corporate Network as well.
2. Finish configuration in SAP Cloud Platform to establish the connection between SAP Cloud Platform and SAP Cloud Connector.
3. Develop Java Web application and deploy onto SAP Cloud Platform.
Architecture as below:

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

Implementation details are listed below.


1. Cloud Connector installation and setup

Download from this url.

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

Once installation is done, launch and ensure it appears in the service list of your OS:

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

Cloud Connector Log on page:

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

Create a new Connector instance, I name it as Jerry_SCC. The Region and Subaccount should be maintained using the corresponding fields of the SAP Cloud Platform to be connected.

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

A created Connector instance looks like below. Click tab “Cloud To On-Premise”:

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

In this UI a mapping relationship is maintained to link a virtual system to ABAP On-Premise system. The virtual system created by me is named as my-backend-system, which points to an internal ABAP system AG3. Specify Protocol as RFC. If everything is correctly maintained, press check button and the status of ABAP system would be marked as Reachable.

Maintain Function Name as STFC, and Naming Policy as Prefix. It means function modules in AG3 with prefix STFC are available for this Connector instance.

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

2. Configuration in SAP Cloud Platform

Now the created Cloud Connector instance is visible in SAP Cloud Platform.
In this step, a destination is created in SCP which will be consumed by my Java application. This destination behaves as the ABAP destination created via tcode SM59.

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

The destination setting could be found below. I name it as my-backend-system-destination, here the user and password in ABAP On-Premise system is filled.

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

Press button “Check Connection” to ensure the destination works as expected.

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

3. Create Java Web application to consume destination created in step 2

The whole source code of this Web application could be found from my github.
Deploy it to SCP.

Brief introduction of core code:

(1) in line 28, get Destination instance by name. The name is specified in step 2.
(2) in line 31, get handle of ABAP function module STFC_CONNECTION.
(3) in line 35, get user input passed via url.
(4) in line 38, fill the user input to importing parameter REQUTEXT of function module STFC_CONNECTION.
(5) in line 42, execute function module.
(6) in line 45, 46, get execution result.

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

Test in Wechat:

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

output:

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

Also set a breakpoint in STFC_CONNECTION to double confirm that it is really called by my Wechat access in mobile phone via RFC:

SAP Cloud Platform, SAP ABAP Guides, SAP ABAP Certification, SAP ABAP Tutorial and Material, SAP ABAP Learning

No comments:

Post a Comment