Skip to Content
-1
Nov 07, 2018 at 05:15 AM

Help with RFC_Read_Table

204 Views

Hi, I'm ussing a similar script like this, but I want to know how can I use the same connection to others Querys

Public Sub RFC_Read_Table()

Dim Functions As Object

Dim RfcCallTransaction As Object

Dim Messages As Object

Dim BdcTable As Object

Dim tblOptions

Dim tblData

Dim tblFields

Dim strExport1

Dim strExport2

Dim filOutput

Dim intRow As Integer

Set Functions = CreateObject("SAP.Functions")

Functions.Connection.System = "PDS"

Functions.Connection.client = "240"

Functions.Connection.user = "S0110028"

Functions.Connection.Password = "0603cacc"

Functions.Connection.Language = "EN"

If Functions.Connection.Logon(0, False) <> True Then

Exit Sub

End If

Set RfcCallTransaction = Functions.Add("RFC_READ_TABLE")

Set strExport1 = RfcCallTransaction.exports("QUERY_TABLE")

Set strExport2 = RfcCallTransaction.exports("DELIMITER")

Set tblOptions = RfcCallTransaction.Tables("OPTIONS") '

Set tblData = RfcCallTransaction.Tables("DATA") '

Set tblFields = RfcCallTransaction.Tables("FIELDS") '

strExport1.Value = "LFBK"

strExport2.Value = ";"

tblOptions.AppendRow

tblOptions(1, "TEXT") = "LIFNR EQ '41'" ' Suppose I want to bank data from vendor number 41.

tblFields.AppendRow

tblFields(1, "FIELDNAME") = "LIFNR"

tblFields.AppendRow

tblFields(2, "FIELDNAME") = "BANKS"

tblFields.AppendRow

tblFields(3, "FIELDNAME") = "BANKL"

tblFields.AppendRow

tblFields(4, "FIELDNAME") = "BANKN"

tblFields.AppendRow

tblFields(5, "FIELDNAME") = "BUTYP"

If RfcCallTransaction.Call = True Then

If tblData.RowCount > 0 Then

Dim DatTxt, OutputTxt As String

OutputTxt = "Vendor, Bank Country, Bank Key, Book No., Run No."

DatTxt = "c:\bankdata.txt"

Open DatTxt For Output As #1

Print #1, OutputTxt

For intRow = 1 To tblData.RowCount

OutputTxt = tblData(intRow, "WA")

Print #1, OutputTxt

Next

Close #1

Else

MsgBox "No records returned"

End If

Else

MsgBox "Error"

End If

Set filOutput = Nothing

Functions.Connection.Logoff

End Sub

I don't know if there's something like Functions.Connection.Back or Functions.Connection.exit