on 11-12-2010 4:45 PM
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
Hi Andreas,
yes it is possible to reuse the connection. But you need to make sure that clean-up all references inside you sub to the reference.
set orfcFunctions.connection = nothing
set orfcfunction = nothing
set sreturn = nothing
set oRfcFunctions = nothing
set osapCon = nothing
Also you Fucntionsmodule must run save, and without a dialog. Because by default the Analyzer Connection is a connection without attached SAP GUI. So calling any GUI functionality ( including GUI_DOWNLOAD etc.) will result in a Shortdump.
best regards
Kai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kai,
Thanks for your replyu2026
But how can I handle this?
I thought following: I want to use the existing BEx Connection to SAP BW also for the librfc32.dll. Thus I have two different Objects, the BEx.Connection and the librf32.Connection. If I set librfc32.Connection equal to Bex.Connection (to use the reference) I should be able to use the same connection for two different objects. But if I run this statement Iu2019ll get the error message u201Cinternal application erroru201D.
In this case the VBA err object has the following entries:
- Description: u201Cinternal application erroru201D
- HelpContext: u201C1061704u201D
- Number: 61704
- Source: u201Cwdtaocxu201D
Sure I can ignore this error message (with the statement ON ERROR RESUME NEXT). In this case I can even make a few successful RFC calls. But if I click on a standard BEx button, Iu2019ll get a fatal application error (and excel crashes).
Regards Alex
Hello,
I'm facing exactly the same problem. It was working fine on Bex 3.5 version but not on the Bex 7.0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexander,
Thank you for the reply, but the problem is that your code could work only if the user launchs the Workbook using Bex Analyser and loged using his user id / password with Sap logon popup.
In my case, the user is connected to SAP application or on a SAP Web Application so the Workbook is launched using RRMX transaction.
In this case we cannot retrieve the password value from the Connection object. It means that this code retrieves nothing:
oRfcFunctions.Connection.Password = oSapCon.Password
In Bex 3.5 I can do this:
Set oSapCon = SAPBEX.BEXgetConnection
Set oRfcFunctions = CreateObject("SAP.Functions")
Set oRfcFunctions.Connection = oSapCon
And it's working fine, but not in BEX 7.0
Best regards,
Edited by: Mourad CHERIFI on Jan 23, 2012 3:50 PM
Hi Alexander,
I have a lower version of SAP GUI but before I install a new one I have a question. What was exactly the problem solved with upgrading SAP GUI ?
Do you mean that the following code is working ?
' 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
Or do you mean that the password retrieving is working even if we launch the workbook through an RRMX call ?
oRfcFunctions.Connection.Password = oSapCon.Password
Thanx
It seems that it's not possible to use only one connection object...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.