SAP RFC 'RFC_READ_TABLE' with variables

bconforto

New Member
Joined
Nov 17, 2016
Messages
30
Hello guys,
i have been reading several post and trying different methods to use SAP RFC_READ_TABLE. I have two sets of code that are running fine, but always passing fixed values as filters.
I would like to have a variable instead.
Maybe some of you could help me on this.
It is clear I am not an expert, but trying to learn.
This one is to check Sales document flow.

Problem is in below line: i would like to filter with VBELV EQ Variable, instead a fixed value.
Code:
tblOptions(1, "TEXT") = "VBELV EQ '0050015909' and VBTYP_N EQ 'I' "

This is the complete running code:

Code:
P
ublic 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
Dim conn As Object
Dim sap As Object
 

Set Functions = CreateObject("SAP.Functions")
Functions.Connection.System = "RR1"
Functions.Connection.client = "010"
Functions.Connection.user = "confob1"
Functions.Connection.Password = "Conforto1"
Functions.Connection.Language = "EN"

If Functions.Connection.logon(0, True) <> 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 = "VBFA"
strExport2.Value = ";"
tblOptions.AppendRow
tblOptions(1, "TEXT") = "VBELV EQ '0050015909' and VBTYP_N EQ 'I' "
tblOptions.AppendRow
 
tblFields.AppendRow
tblFields(1, "FIELDNAME") = "VBELN"

If RfcCallTransaction.Call = True Then
If tblData.RowCount > 0 Then
For intRow = 1 To tblData.RowCount
OutputTxt1 = tblData(intRow, "WA")
Next

Else
MsgBox "No records returned"
End If
Else
MsgBox "Error"
End If
Set filOutput = Nothing
Functions.Connection.Logoff
End Sub

Thank you very much for your help,
Brian
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Code:
Dim var As String
var = "0050015909"
tblOptions(1, "TEXT") = "VBELV EQ '" & var & "' and VBTYP_N EQ 'I' "
 
Upvote 0
Thank you Sektor, that code is working.

When Sales Document is save, also with my macro, i take from the output message the number as 50015909.
So var = 50015909.
How do I format var to a ten digits lenght with leading zeros?

Regards,
Brian
 
Upvote 0
Code:
Sub KKK()
    Dim var As String
    var = "50015909"
    var = String(10 - Len(var), "0") & var
    MsgBox var
End Sub
 
Upvote 0
Thank you again.
I also tried this and worked.

Code:
a = Format(valuetoformat, "0000000000")

Regards,
Brian
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,709
Members
449,118
Latest member
MichealRed

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top