Code: Alles auswählen.
Sub RFCReadTable()
' https://www.linkedin.com...rom-ms-excel-erkan-kopuz
' https://saplsmw.com/Impo...cess_from_SAP_using_RFCs
' http://sapass.metro.clie...X/UseFunctionControl.htm
Set oSap = CreateObject("SAP.Functions")
oSap.Connection.ApplicationServer = "**" ' IP des Appl-Servers (SM51->Details)
oSap.Connection.SystemNumber = "**" ' Systemnummer, meißt im Namen des Appl-Servers enthalten
oSap.Connection.System = "**" ' Entwicklungs-, Test-, Produktivsystem
oSap.Connection.Client = "**" ' Mandant
oSap.Connection.Language = "**" ' Sprache "EN", "DE" ...
oSap.Connection.User = "**" ' SAP-User
oSap.Connection.Password = "**" ' 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, True) = True Then
Dim oFuBa As Object
' FuBa RFC_READ_TABLE abfragen
Set oFuBa = oSap.Add("RFC_READ_TABLE")
' EXPORTING
Set e_query_table = oFuBa.Exports("QUERY_TABLE")
Set e_delimiter = oFuBa.Exports("DELIMITER")
Set e_rowCount = oFuBa.Exports("ROWCOUNT")
e_query_table.Value = "AFRU" ' Tabelle AFRU
e_delimiter.Value = ";" ' Spalten mit ";" getrennt
e_rowCount.Value = "0" ' max. 100 Datensätze lesen, 0 = alle
' TABLES
Set t_options = oFuBa.Tables("OPTIONS")
Set t_fields = oFuBa.Tables("FIELDS")
' WHERE-Bedingung
t_options.AppendRow
' t_options(1, "TEXT") = "TDOBJECT EQ 'TEXT'"
t_options(1, "TEXT") = "AUFNR EQ '000001228621' AND ISM02 > '0'"
' Welche Spalten sollen gelesen werden
t_fields.AppendRow
t_fields(1, "FIELDNAME") = "AUFNR"
t_fields.AppendRow
t_fields(2, "FIELDNAME") = "RUECK"
t_fields.AppendRow
t_fields(3, "FIELDNAME") = "ISM02"
t_fields.AppendRow
t_fields(4, "FIELDNAME") = "PERNR"
If oFuBa.Call = True Then
' Schnittstellenparameter "TABLES-DATA" holen
' Rückgabe in Excel-Sheet einfügen
Dim iRow As Integer
iRow = 1
Set t_data = oFuBa.Tables("DATA") // ET_DATA needed...
' Rückgabemenge beinhaltet Strings, die mit dem festgelegten Separator ";" getrennt sind
For Each Row In t_data.Rows
' Spalten einer Datenzeile anhand des Separators ";" aufsplitten
Dim vFields As Variant
vFields = Split(t_data.Rows(1), ";")
' Inhalt der Spalten in die Zellen schreiben
For iCol = LBound(vFields) To UBound(vFields)
ActiveWorkbook.Sheets(1).Cells(iRow, iCol + 1) = Trim(vFields(iCol))
Next iCol
iRow = iRow + 1
Next
Else
' Exception?
MsgBox oFuBa.Exception
End If
' Logoff
oSap.Connection.logoff
Else
' Kein Login möglich
MsgBox "Login fehlgeschlagen."
End If
End Sub