How to use SAP RFM with SAP NCo via Invoke Code in UiPath

Today I want to check how to call a remote enabled function module. That is much more easier than it seems. At first I developed a VBdotNET code to connect an SAP system and to call a remote enabled function module.

'-Begin-----------------------------------------------------------------

Dim cfgParams As SAP.Middleware.Connector.RfcConfigParameters
Dim destination As SAP.Middleware.Connector.RfcDestination
Dim rfcFunction As SAP.Middleware.Connector.IRfcFunction

cfgParams = New SAP.Middleware.Connector.RfcConfigParameters
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Name, "Test" )
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.AppServerHost, "ABAP702")
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.SystemNumber, "00")
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Client, "001")
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.User, "BCUSER")
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Password, "minisap")

destination = SAP.Middleware.Connector.RfcDestinationManager.GetDestination(cfgParams)

rfcFunction = destination.Repository.CreateFunction("STFC_CONNECTION")
rfcFunction.SetValue("REQUTEXT", "Hello World from UiPath Studio via SAP")
rfcFunction.Invoke(destination)

echoText = rfcFunction.GetValue("ECHOTEXT").ToString()
respText = rfcFunction.GetValue("RESPTEXT").ToString()

'-End-------------------------------------------------------------------

In this example I call the remote enabled function module STFC_CONNECTION. At first I define the connection parameter to the SAP system. Then the import parameter is defined, it imports REQUTEXT. After the execution of the RFM it exports ECHOTEXT and RESPTEXT. As you can see ECHOTEXT is only a copy of REQUTEXT and RESPTEXT contains a few SAP system fields.

Here the flow chart, only with the Invoke Code and two Write Line activities.

And here the result :slightly_smiling_face:

Output

My gosh, it can hardly be easier to call an SAP RFM.

4 Likes

@StefanSchnell:- Adding Method 2 To connect SAP Using Invoke Code

Method-2 :- Using SAP GUI Scripting


This is For those who want to Automate the SAP GUI and are only able to do so through VBA and VB.Net. Here is a simple solution to automate SAP using Vb.Net Invoke Code:

First add two references:
SAPFEWSELib
SapROTWr <---- This one is located in the folder where SAP was installed.

Attached the Below Script for reference

Sap_Logon.zip (12.0 KB)

Regards
Sanjay

2 Likes