cancel
Showing results for 
Search instead for 
Did you mean: 

Use one connection object for BEx Analyzer and a RFC-Call

alexander_stettler
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

alexander_stettler
Participant
0 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

I'm facing exactly the same problem. It was working fine on Bex 3.5 version but not on the Bex 7.0

alexander_stettler
Participant
0 Kudos

Hi Mourad,

Sorry! But we use only BEx 7.x. In our case we've implemented the coding (code snippet 2 above) in several of our workbooks and have no issues with it...

Regards,

Alex

Former Member
0 Kudos

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

alexander_stettler
Participant
0 Kudos

Hi Mourad,

I know your issue. We had the same one in the middle of the last year. Luckily we could solve it though an upgrade of the SAP GUI...

Best Regards,

Alex

Former Member
0 Kudos

Hi Alexander,

Could you tell me which version of SAP GUI you are using ?

Thanx

alexander_stettler
Participant
0 Kudos

Hi Mourad,

Right now we are on

SAP GUI 7.20 Patch-Level 6

and

BI AddOn 7.X (based on 7.20) Support Package 4 Patch 1...

Regards,

Alex

Former Member
0 Kudos

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

alexander_stettler
Participant
0 Kudos

With the SAP GUI upgrade we were able to fix the issue with the RRMX.

The other issue will still exist after your upgrade. It looks as if it is not possible to use the same connection - At least we could not found a solution...

alexander_stettler
Participant
0 Kudos

It seems that it's not possible to use only one connection object...