Hallo Community, 
 
ich habe das folgende Problem: 
 
Ich versuche den Funktionsbaustein RFC_READ_TABLE in Excel über VBA in einer Schleife für mehrere Tabellen nacheinander ablaufen zu lassen. Bei der ersten Tabelle (z.B.: A861) funktioniert alles einwandfrei, bei der nächsten Tabelle (z.B.: KONP) bekomme ich aber die Meldung FIELD_NOT_VALID. Das passiert auch wenn ich die gleiche Tabelle zweimal abfrage. Komischerweise, wenn ich in die Schleife eine nochmalige Anmeldung im SAP einbaue funktioniert es.
Ich versuche zu einer Zugriffsfolgetabelle z.B.: A861 mit dem Feld KNUMH über die Tabelle KONP den richtigen Konditionswert zu selektieren. 
 
Habt Ihr eine Lösung ? Ich komme seit einer Woche nicht mehr weiter. Ich hab schon alles mögliche probiert. Für einen guten Tipp wäre ich dankbar 
 
Grüsse 
Rafael
Vorher wird ein Anmeldung im SAP durchgeführt.
 Anbei das VBA-Script:
Sub GetTableFieldsData(ByRef iTableName, _ 
 ByRef functionCtrl, _ 
 ByRef colKondTables, _ 
 ByRef StatusKond) 
 
Dim theFunc As Object 
Dim OPTIONS As Object 
Dim iTableFields As Object 
Dim iTableData As Object 
 
Dim iFieldName As Variant 
Dim iField As Variant 
Dim Row As Variant 
Dim iKondition As Variant 
Dim iWert As Variant 
 
Dim die_exception As String 
 
Dim returnFunc As Boolean 
 
Dim iTablesStrukt As New Collection 
Dim colField As New Collection 
Dim colLength As New Collection 
Dim colOffset As New Collection 
 
Dim iMaxSatz As Double 
 
Dim iLength As Integer 
Dim iOffset As Integer 
Dim icol As Integer 
Dim startzeil As Integer 
Dim s As Integer 
Dim ColCounter As Integer 
Dim i As Integer 
 
 
startzeil = 4 
ColCounter = 1 
i = startzeil 1 
s = 2 
Cells(4, 1) = "TABLE" 
Range(Cells(startzeil, 1), Cells(startzeil, 60)).Font.Bold = True 
 
If StatusKond = True Then 
 iKondition = iTableName 
 iTableName = "T682I" 
End If 
 
 Set theFunc = functionCtrl.Add("RFC_READ_TABLE") 
 theFunc.exports("QUERY_TABLE") = iTableName 
  
 If StatusKond = True Then 
 Set OPTIONS = theFunc.tables("OPTIONS") 
 OPTIONS.Rows.Add 
 OPTIONS.Value(1, "TEXT") = "KOZGF = '" & iKondition & "'" 
 End If 
  
 returnFunc = theFunc.Call 
 die_exception = theFunc.Exception 
 
 If returnFunc = True Then 
  
 ' Liest Tabellenfelder 
  
 Set iTableData = theFunc.tables.Item("DATA") 
 Set iTableFields = theFunc.tables.Item("FIELDS") 
  
 For Each iField In iTableFields.Rows 
  
 iLength = Trim(iField("LENGTH")) 
 iOffset = Trim(iField("OFFSET")) 
 iFieldName = Trim(iField("FIELDNAME")) 
  
 colField.Add (iFieldName) 
 colLength.Add (iLength) 
 colOffset.Add (iOffset) 
  
 If Not StatusKond = True Then 
 Cells(3, s) = Trim(iField("FIELDTEXT")) 
 Cells(4, s) = Trim(iField("FIELDNAME")) 
 s = s 1 
 End If 
  
 Next 
  
 'Zerschneidet den iWert nach Länge und Offset 
  
 For Each Row In iTableData.Rows 
 iWert = Row("WA") 
  
 If StatusKond = True Then 
 If Mid(Trim(iWert), colOffset(3) 1, colLength(3)) = iKondition Then 
 colKondTables.Add "A" & Mid(Trim(iWert), colOffset(5) 1, colLength(5)) 
 End If 
 End If 
  
 Do While ColCounter < s - 1 
  
 iFieldName = colField.Item(ColCounter) 
 iOffset = colOffset.Item(ColCounter) 1 
 iLength = colLength.Item(ColCounter) 
  
 iWert = Mid(Trim(Row("WA")), iOffset, iLength) 
 iWert = "'" & iWert 
  
 'Datumsfeld richtig darstellen 
 If iFieldName = "DATBI" Or iFieldName = "DATAB" Then 
 iWert = Left(iWert, 5) & "-" & Mid(iWert, 6, 2) & "-" & Right(iWert, 2) 
 End If 
  
 Cells(i, ColCounter 1) = iWert 'Werte der Zugriffsfolgetabelle in Spalte 2 
 Cells(i, 1) = iTableName 'Name der Zugriffsfolgetabelle in Spalte 1 
  
 ColCounter = ColCounter 1 
  
 If iFieldName = "KNUMH" Then 
 Call GetKNUMH(functionCtrl, ColCounter, startzeil, iWert, die_exception) 
 If die_exception = "NO_RECORDS_FOUND" Then 
 Cells(i, ColCounter 1) = "--" 
 Else 
 If die_exception = "" Then 
 Cells(i, ColCounter 1) = iWert 
 End If 
 End If 
 End If 
  
 frmImportValues.Label5.Caption = "Lese Tabelle..." & iTableName 
 frmImportValues.Import_kond.Width = 0 
 frmImportValues.Frame_I.Width = 200 
 frmImportValues.Import_kond.Width = Row.Index / iTableData.RowCount * 200 
 frmImportValues.Import_percent = Round(Row.Index / iTableData.RowCount * 100, 0) 
 DoEvents 
 Loop 
  
 If i = iMaxSatz startzeil Then Exit For 
 ColCounter = 1 
 i = i 1 
 Next 
  
 Else 
 Call Fehler(die_exception) 
 End If 
  
 Set iTableFields = Nothing 
 Set iTableData = Nothing 
 Set OPTIONS = Nothing 
 Set theFunc = Nothing 
End Sub 
 
Sub Fehler(ByRef die_exception) 
 
 If die_exception = "NO_RECORDS_FOUND" Then 
 Exit Sub 
 Else 
 MsgBox "Fehler beim Zugriff auf Funktion im R/3 ! " & die_exception 
 Exit Sub 
 End If 
  
End Sub 
 
Sub GetKNUMH(ByRef functionCtrl, _ 
 ByRef ColCounter, _ 
 ByRef startzeil, _ 
 ByRef iWert, _ 
 ByRef die_exception) 
 
Dim colField As New Collection 
Dim colLength As New Collection 
Dim colOffset As New Collection 
 
Dim iLength As Integer 
Dim iOffset As Integer 
 
Dim iFieldName As String 
 
iTableName = "KONP" 
 
 iWert = Mid(iWert, 2, 15) 
 Set theFunc = functionCtrl.Add("RFC_READ_TABLE") 
 theFunc.exports("QUERY_TABLE") = iTableName 
  
 Set OPTIONS = theFunc.tables("OPTIONS") 
 OPTIONS.Rows.Add 
 OPTIONS.Value(1, "TEXT") = "KNUMH = '" & iWert & "'" 
  
  
 returnFunc = theFunc.Call 
 die_exception = theFunc.Exception 
 
 If returnFunc = True Then 
  
 ' Liest Tabellenfelder 
  
 Set iTableData = theFunc.tables.Item("DATA") 
 Set iTableFields = theFunc.tables.Item("FIELDS") 
  
 For Each iField In iTableFields.Rows 
  
 iLength = Trim(iField("LENGTH")) 
 iOffset = Trim(iField("OFFSET")) 
 iFieldName = Trim(iField("FIELDNAME")) 
  
 colField.Add (iFieldName) 
 colLength.Add (iLength) 
 colOffset.Add (iOffset) 
  
 Next 
  
 'Zerschneidet den iWert nach Länge und Offset 
  
 For Each Row In iTableData.Rows 
 iWert = Row("WA") 
  
 If StatusKond = True Then 
 If Mid(Trim(iWert), colOffset(3) 1, colLength(3)) = iKondition Then 
 iWert = Mid(Trim(iWert), colOffset(5) 1, colLength(5)) 
 End If 
 End If 
 Next 
 Else 
 Call Fehler(die_exception) 
 End If 
  
End Sub