0
votes

I am trying to connect to SAP via RFC objects:

Dim sap As Object
Set sap = CreateObject("SAP.Functions.unicode")
sap.connection.system = "xxxxxxxx"
sap.connection.Client = "700"
sap.connection.User = "USER"
sap.connection.Password = "PASS"
sap.connection.Language = "EN"

If sap.connection.Logon(1, False) <> True Then 'Try Logon
   MsgBox "Cannot Log on to SAP"
End If

'*************************************************************
'Define the table specifics
'************************************************************

Dim objRfcFunc As Object
Set objRfcFunc = sap.Add("RFC_READ_TABLE") 'IN THIS LINE MY ERROR OCCURS

Internal application error - runtime error:61704

Any solutions?

connection parametersIt seems like my connection is OK. Could you check my connection variables?

1
When you run it, I presume you don't get the message "Cannot Log on to SAP", right? Is there any reason why you use ...Logon(1,False) instead of ...Logon(0,False)? (it's a hWND argument, to refer to a Windows dialog window, but I always saw people use 0; note that the boolean is for silent exceptions)Sandra Rossi
Your screenshot does not contain any variable from your code! How comes?Storax

1 Answers

1
votes

The following code I took from here and adjusted it worked for me. Of course you have to change the connection parameters (username etc.) as well. I guess your issue is you do not have a connection in the first place.

Sub Test_RFC()
    ' Connect to SAP
    Dim oSAP As Object
    Set oSAP = CreateObject("SAP.Functions.unicode")
    ' Connection parameters - to be adjusted
    oSAP.Connection.ApplicationServer = "1.1.1.1" ' IP des Appl-Servers (SM51->Details)
    oSAP.Connection.SystemNumber = "01"           ' Systemnummer, meißt im Namen des Appl-Servers enthalten
    oSAP.Connection.System = "XD1"                ' Entwicklungs-, Test-, Produktivsystem
    oSAP.Connection.Client = "100"                ' Mandant
    oSAP.Connection.Language = "DE"               ' Sprache "EN", "DE" ...



    ' RFC-Login: Show logon popup
    If oSAP.Connection.Logon(0, False) = True Then
        'You can only add a function module in case you have a connection
        Dim oFuBa As Object            
        Set oFuBa = oSAP.Add("RFC_READ_TABLE")

    End If
End Sub