ich möchte aus SAP eine Zeitdaten (unter Zeiterfassung) per VBA auslesen, dann in EXCEL übergeben.
Anmledung (unter EXCEL per VBA) läuft gut, aber wie gehe ich weiter?
Vielen Dank im Voraus
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
Sub test()
Dim functionCtrl As Object
Dim sapConnection As Object
Dim FUBAU_rfc_read_table 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 sapConnection = functionCtrl.Connection
sapConnection.Client = "100"
sapConnection.User = "***"
sapConnection.Password = "***"
sapConnection.Language = "DE"
sapConnection.SystemNumber = 1
sapConnection.System = "***"
If sapConnection.Logon(1, True) True Then
MsgBox "Keine Verbindung zum SAP!"
Exit Sub
End If
Set FUBAU_rfc_read_table = functionCtrl.Add("RFC_READ_TABLE")
With FUBAU_rfc_read_table
.exports("QUERY_TABLE") = "P2011" '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
Set FUBAU_rfc_read_table = functionCtrl.Add("RFC_READ_TABLE")
With FUBAU_rfc_read_table
.exports("QUERY_TABLE") = "USR01" 'InputBox("Bitte Tabellenname eingeben")
.exports("DELIMITER") = "|" 'Delimiter
End With
ref=False und T_E_Data.RowCount = 0
sapConnection.Logon = True