"Resetting" a function...(How to close after FuncC

Question: Hi,
In VBA I have an iterative process in which I call a RFC-Function.

If I do this without login out of the SAP system (and login in of course), the information of the 'Table' just gets added in the result.

I think it has to do with the fact that I don't reset my Function Call, but I don't find how I can do this...

Some snippits:

First: A (big) part of the function


Private Sub SAP_LLI(ByVal strMatNr As String, ByVal Date1 As String, ByVal Date2 As String)
   Set theFunc = functionCtrl.Add("MyRFCFunc")
   
    theFunc.exports("Mat") = strMatNr
    theFunc.exports("Date1") = Date1
    theFunc.exports("Date2") = Date2
   
    FuncResult = theFunc.Call

    FuncError = theFunc.Exception

    If FuncResult = True Then
        For Each veld In theFunc.tables("TABUIT").Rows
            Cells(teller, 1) = strMatNr
            Cells(teller, 2) = veld("BWART")
            Cells(teller, 3) = veld("MBLNR")
            Cells(teller, 4) = veld("DATUM")
            Cells(teller, 5) = veld("MJAHR")
            Cells(teller, 6) = veld("LIFNR")
            Cells(teller, 7) = veld("NAME1")
            Cells(teller, 8) = veld("MENGE")
            Cells(teller, 9) = veld("MEINS")
            Cells(teller, 10) = veld("EBELN")
            Cells(teller, 11) = veld("EBELP")
            teller = teller + 1
        Next
    Else
        MsgBox FuncError
    End If
End Sub



Secondly: The iterative call, like I want it to be

Function SAP_LLI_R40()
    If SAPLoginR40 Then
        Date1 = "20060404"
        Date2 = "20060901"
        For MatCount = 1 To 28
            Call SAP_LLI(Sheets("MatNrs").Range("A" & MatCount).Value, Date1, Date2)
        Next
        Call SAPLogoff(False)
    End If
End Function



The Table TABUIT just keeps growing with each call, and in the ABAP there is a clear TABUIT programmed in the function...

Anyone an idea on how I can solve this ? (without logout & login ; the following function does the trick as well)

'Function SAP_LLI_R40()
    For MatCount = 1 To 28
    If SAPLoginR40 Then
        Date1 = "20060404"
        Date2 = "20060901"
        Call SAP_LLI(Sheets("MatNrs").Range("A" & MatCount).Value, Date1, Date2)
        Call SAPLogoff(False)
    End If
    Next
End Function


Answer:
I think you can do with FreeTable method just after the completion of for/next loop.
theFunc.tables("TABUIT").FreeTable

Or remove function after the loop like below.
theFunc("MyRFCFunc").Remove

R,
mas
_________________
Excel & SAP - http://sapass.metro.client.jp
Copyright ?2007 - 2008 www.jt77.com