Skip to Content
avatar image
Former Member

call RFC_READ_TABLE via VBA.

I try to get data from table LFBK (bank data for vendor).

Here is my VBA code to get data, it's not works. Anyone can suggest me what's wrong? Thank you very much.

Anek

'**************************************

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    Apr 01, 2006 at 07:33 AM

    is it not connecting to the system or the problem is with executing the FM

    Raja

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Angel Garcia

      Hello Raj,

      I too working on same but i am automating the report with date but no success i tried with sy-datum its fine but i want it with sy-datum -1 , for previous day data to be fetch from sap. Please help

      Regards

      Chetan S.