Skip to Content
Former Member
May 15, 2018 at 07:30 AM

RFC_READ_TABLE - can´t get silent login to work...


Hello everybody,

I have a code in an excel file that I use to gather data from tables. For this I´m using RFC_READ_TABLE. The active login via popup works like a charm, however any attempt to get it working via silent login utterly fails. My script is complex and long, chaining multiple tables along and gathering mass amounts of data, that is why I spare you with my code and provide an easy example from the internet.

Basically the problem is here:

If oSAP.Connection.Logon(0, False) = True Then

When set to false, it asks me for credentials. When I provide them, everything is fine.

When I however set it to:

If oSAP.Connection.Logon(0, True) = True Then

I receive an error 1001 exactly here:

 Set oFuBa = oSAP.Add("RFC_READ_TABLE")

I suspect my login is somehow not working, maybe wrong application server - I do not know.

When I login via popup & credentials, my application server is empty and my login is working perfectly.

Does anybody know, why the silent login is not working in this example code? Is the application server mandatory? Why does it work with empty application server as long as the popup is used?

I´d be glady if anybody could lend me a hand here. Thank you very much in advance.

Sub RFCReadTable()
    Set oSAP = CreateObject("SAP.Functions")
    oSAP.Connection.ApplicationServer = "" ' IP des Appl-Servers (SM51->Details)
    oSAP.Connection.SystemNumber = "01"           ' Systemnummer, meißt im Namen des Appl-Servers enthalten
    oSAP.Connection.System = "XA1"                ' Entwicklungs-, Test-, Produktivsystem
    oSAP.Connection.Client = "100"                ' Mandant
    oSAP.Connection.Language = "DE"               ' Sprache "EN", "DE" ...
    oSAP.Connection.User = "USER1"                ' SAP-User
    oSAP.Connection.Password = "xyz"              ' SAP-Passwort
    oSAP.Connection.UseSAPLogonIni = False
    ' RFC-Login, wobei
    ' Logon(0, False): Logon-Fenster anzeigen
    ' Logon(0, True): Silent logon, Passwort muss gesetzt sein
    If oSAP.Connection.Logon(0, False) = True Then
      Dim oFuBa As Object
      ' FuBa RFC_READ_TABLE abfragen
      Set oFuBa = oSAP.Add("RFC_READ_TABLE")
      Set e_query_table = oFuBa.Exports("QUERY_TABLE")
      Set e_delimiter = oFuBa.Exports("DELIMITER")
      Set e_rowCount = oFuBa.Exports("ROWCOUNT")
      e_query_table.Value = "STXH" ' Tabelle STXH
      e_delimiter.Value = ";"      ' Spalten mit ";" getrennt
      e_rowCount.Value = "100"     ' max. 100 Datensätze lesen, 0 = alle
      ' TABLES
      Set t_options = oFuBa.Tables("OPTIONS")
      Set t_fields = oFuBa.Tables("FIELDS")
      Set t_data = oFuBa.Tables("DATA")
      ' WHERE-Bedingung
      t_options(1, "TEXT") = "TDOBJECT EQ 'TEXT'"
      ' Welche Spalten sollen gelesen werden
      t_fields(1, "FIELDNAME") = "TDOBJECT"
      t_fields(2, "FIELDNAME") = "TDNAME"
      t_fields(3, "FIELDNAME") = "TDID"
      t_fields(4, "FIELDNAME") = "TDTITLE"
      t_fields(5, "FIELDNAME") = "TDLUSER"
      If oFuBa.Call = True Then
        ' Schnittstellenparameter "TABLES-DATA" holen
        ' Rückgabe in Excel-Sheet einfügen
        Dim iRow As Integer
        iRow = 1
        ' Rückgabemenge beinhaltet Strings, die mit dem festgelegten Separator ";" getrennt sind
        For Each oDataLine In t_data.Rows
          Dim vFields As Variant
          vFields = Split(oDataLine(1), ";")
          For iCol = LBound(vFields) To UBound(vFields)
            ActiveWorkbook.Sheets(1).Cells(iRow, iCol + 1) = Trim(vFields(iCol))
          Next iCol
         iRow = iRow + 1
        ' Exception?
        MsgBox oFuBa.Exception
      End If
      ' Logoff
      ' Login not possible
      MsgBox "Login failed"
    End If
End Sub