Hi at all,
we want to execute an RFC function module in our SAP BW out of the BEx Analyzer. For this, I tried to use the existing BEx Connection in combination with the SAP.Functions.Connection (LIBRFC32.dll) object (have a look to the code snippet 1). Unfortunately I always get an exception...
Code snippet 1:
' Get the existing Bex Connection
Set oSapCon = Run("BExAnalyzer.XLA!sapBEXgetConnection")
' Create a 'SAP.Functions' objcet
Set oRfcFunctions = CreateObject("SAP.Functions")
' Get the current Connection to SAP
Set oRfcFunctions.Connection = oSapCon
If I use only the parameter of the BEx connection and create a new connection for the SAP.Functions object (have a look to code snippet 2) all will work fine - But in this case I have two different connections from my Excel file to SAP BW.
Isn't it possible to use only one connection for the BEx and the RFC Call?
Code snippet 2:
Public Sub execRfcTest()
Dim oSapCon As Object
Dim oRfcFunctions As Object
Dim oRfcCallFunction As Object
Dim sReturn As Object
' RFC Funktions Objekt erzeugen
Set oSapCon = Run("BExAnalyzer.XLA!sapBEXgetConnection")
Set oRfcFunctions = CreateObject("SAP.Functions")
'oRfcFunctions.Connection = oSapCon
oRfcFunctions.Connection.ApplicationServer = oSapCon.ApplicationServer
oRfcFunctions.Connection.Password = oSapCon.Password
oRfcFunctions.Connection.client = oSapCon.client
oRfcFunctions.Connection.user = oSapCon.user
oRfcFunctions.Connection.Language = oSapCon.Language
oRfcFunctions.Connection.hostname = oSapCon.hostname
oRfcFunctions.Connection.SystemNumber = oSapCon.SystemNumber
oRfcFunctions.Connection.System = oSapCon.System
oRfcFunctions.Connection.Destination = oSapCon.Destination
' Aufbau der Verbindung
If oRfcFunctions.Connection.Logon(0, True) <> True Then
Exit Sub
End If
' Funktionsbaustein bekannt geben
Set oRfcCallFunction = oRfcFunctions.Add("ZBI_RFC_TEST")
' Input Parameter setzten
oRfcCallFunction.exports("LV_INPUT") = Range("C7").Value2
' Aufruf des Funktionsbausteins
If oRfcCallFunction.call = True Then
Set sReturn = oRfcCallFunction.imports("LV_RETURN")
Range("C8").Value2 = sReturn.Value
Else
Call MsgBox("Error!!!")
End If
oRfcFunctions.Connection.Logoff
End Sub