One Way how to use SAP Remote Function Calls (RFC) with UiPath

sap

#1

Since a few days I test UiPath studio to learn the basics of it. A great tool. In the context of my tests I asked myself: How could it be possible to call remote enabled function modules from an SAP backend system? So I use my approach which I described in the SAP Community four years ago. I used PowerShell in combination with SAP dotNET Connector (NCo). It works great and on this way it is absolut easy possible to communicate from UiPath, via PowerShell and NCo, with an SAP backend system.
Here a tiny PowerShell script which calls an RFM in an SAP system:

#-Begin-----------------------------------------------------------------

Param(
  [String]$Message
)

#-Sub Load-NCo----------------------------------------------------------
Function Load-NCo {

  [String]$ScriptDir = "C:\Dummy\"

  If ([Environment]::Is64BitProcess) {
    [String]$Path = $ScriptDir + "\x64\"
  } Else {
    [String]$Path = $ScriptDir + "\x86\"
  }

  [String]$File = $Path + "sapnco.dll"; Add-Type -Path $File
  $File = $Path + "sapnco_utils.dll"; Add-Type -Path $File

}

#-Function Get-Destination----------------------------------------------
Function Get-Destination {

  #-Verbindungsparamter-------------------------------------------------
  $cfgParams = `
    New-Object SAP.Middleware.Connector.RfcConfigParameters
  $cfgParams.Add($cfgParams::Name, "TEST")
  $cfgParams.Add($cfgParams::AppServerHost, "ABAP702")
  $cfgParams.Add($cfgParams::SystemNumber, "00")
  $cfgParams.Add($cfgParams::Client, "001")
  $cfgParams.Add($cfgParams::User, "BCUSER")
  $cfgParams.Add($cfgParams::Password, "minisap")

  Return [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)

}

#-Sub Invoke-SAPFunctionModule------------------------------------------
Function Invoke-SAPFunctionModule {

  $destination = Get-Destination
  $rfcFunction = `
    $destination.Repository.CreateFunction("STFC_CONNECTION")
  $rfcFunction.SetValue("REQUTEXT", "$($Message)")
  $rfcFunction.Invoke($destination)
  [String]"$($rfcFunction.GetValue("ECHOTEXT"))`r`n$($rfcFunction.GetValue("RESPTEXT"))"

}

#-Sub Main--------------------------------------------------------------
Function Main {
  If ($PSVersionTable.PSVersion.Major -ge 5) {
    Load-NCo
    Invoke-SAPFunctionModule
  }
}

#-Main------------------------------------------------------------------
Main

#-Error routine---------------------------------------------------------
Trap {
  [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") > $Null
  [Void] [System.Windows.Forms.MessageBox]::Show( `
    $_.Exception.GetType().FullName + `
    [System.Environment]::NewLine + `
    "Error at line " + $_.InvocationInfo.ScriptLineNumber + `
    " in " + $_.InvocationInfo.ScriptName + `
    [System.Environment]::NewLine + [System.Environment]::NewLine + `
    $_.Exception.Message, "An Error Occurred", 0)
  Exit
}

#-End-------------------------------------------------------------------

The script calls the RFM STFC_CONNECTION which echos a text and delivers a few technical information.
On this way you can use RFM calls very easily.