AW: VBA auf SAP R3 zugreifen ?
14.08.2019 09:00:54
ede
Hallo Jana,
anbei mal ein Beispiel, wie man den Inhalt einer Tabelle nach Excel holt:
Sub ReadTable()
Dim FUBAU_rfc_read_table As Object
Dim functionCtrl As Object
Dim T_I_Options As Object
Dim T_I_Fields As Object
Dim T_E_Data As Object
Dim i, x As Integer
Dim strDataRow As String
Dim DataRow As Variant
Dim Col As Boolean
Col = False
Set functionCtrl = CreateObject("SAP.Functions")
Set FUBAU_rfc_read_table = functionCtrl.Add("RFC_READ_TABLE")
With FUBAU_rfc_read_table
.exports("QUERY_TABLE") = InputBox("Bitte Tabellenname eingeben")
.exports("DELIMITER") = "|" 'Delimiter
End With
Set T_I_Options = FUBAU_rfc_read_table.tables("OPTIONS")
Set T_I_Fields = FUBAU_rfc_read_table.tables("FIELDS")
Set T_E_Data = FUBAU_rfc_read_table.tables("DATA")
'Aufruf des FUBAs
ret = FUBAU_rfc_read_table.call
'Übetragen der Daten in Excel-Tabelle (z.B. immer in Tabelle1)
If T_E_Data.RowCount > 0 And ret = True Then
For i = 1 To T_E_Data.RowCount
strDataRow = T_E_Data(i, 1)
DataRow = Split(strDataRow, "|")
'Spaltenüberschriften an Excel übergeben
If Col = False Then
For x = 0 To UBound(DataRow)
Tabelle1.Cells(1, x + 1).Value = T_I_Fields(x + 1, 1)
Next x
Col = True
End If
For x = 0 To UBound(DataRow)
Tabelle1.Cells(i + 1, x + 1).Value = DataRow(x)
Next x
Next i
End If
End Sub
Logindaten für DEIN SAP SYSTEM anpassen
Public Sub Anmelden_an_SAP()
SAP_Anmeldung = False
Set functionCtrl = CreateObject("SAP.Functions")
Set SAP_Connection = functionCtrl.Connection
SAP_Connection.ApplicationServer = "DEINSERVER"
SAP_Connection.SystemNumber = "20"
SAP_Connection.System = "DEINSYSTEM"
SAP_Connection.Client = "002"
SAP_Connection.User = "DeinName" ' SAP_UserID
SAP_Connection.Password = "DeinKennwort" 'SAP_Passwort
If SAP_Connection.Logon(0, True) True Then
'Nur wenn keine Verbindung zu SAP kommt eine Fehlermeldung
SAP_Connection.LastError
SAP_Anmeldung = False
Else
SAP_Anmeldung = True
End If
'MsgBox SAP_Anmeldung
End Sub
gruss
ede