user3213199
user3213199

Reputation: 21

VBA to SAP // RFC function module with table as Input Parameter

I want to send data from Excel via a RFC-Connector to SAP software.

For the RFC function module, I must fill a table as an input parameter. Comparable to the RFC function module STFC_DEEP_TABLE.

My VBA code stops at the with statement with the error:

“Object variable or With block variable not set”.

Sub RFC_DEEP_TABLE()
Dim sapConn As Object
Set sapConn = CreateObject("SAP.Functions")

If sapConn.Connection.Logon(0, False) <> True Then
    MsgBox "Cannot Log on to SAP"
End If

Dim objRfcFunc As Object
Set objRfcFunc = sapConn.Add("STFC_DEEP_TABLE")

With objRfcFunc
    .Exports.Item("IMPORT_TAB").value("STR") = "X" 'Objectvariable oder With-Blockvariable nicht festgelegt
End With

If objRfcFunc.Call = False Then
    MsgBox objRfcFunc.Exception
End If

End Sub

Upvotes: 2

Views: 4064

Answers (3)

Matthew Walker
Matthew Walker

Reputation: 1

I have an example used with the BAPI RFC_READ_TABLE.

'// SAP FUNCTION
Set fns = CreateObject("SAP.Functions")
Set conn = fns.connection

Set objRfcFunc = fns.Add("RFC_READ_TABLE")
Set objQueryTab = objRfcFunc.Exports("QUERY_TABLE")
Set objRowCount = objRfcFunc.Exports("ROWCOUNT")

objRowCount.value = "999999"

'// FUNCTION OBJECTS
Set objOptTab = objRfcFunc.Tables("OPTIONS")
Set objFldTab = objRfcFunc.Tables("FIELDS")
Set objDatTab = objRfcFunc.Tables("DATA")

'// TABLE
objQueryTab.value = "LQUA"

'// CRITERIA
objOptTab.FreeTable
objOptTab.Rows.Add
objOptTab(objOptTab.RowCount, "TEXT") = "LGNUM = 312"

So, you could try using as a template?

Upvotes: 0

Barbara_Munich
Barbara_Munich

Reputation: 1

I had the same problem, that I could not instantiate the BAPI. The SAP guys altered the BAPI, and I could access it without altering the code.
BTW: the parameter order is:

 import_tab.cell(line#, fieldname) = "X"

Upvotes: 0

Dirk Trilsbeek
Dirk Trilsbeek

Reputation: 6033

I can't test this, but from reading up on VBA/SAP Net Connector, it looks like you, similar to the .Net Connector syntax for C#, have to add a row to an import table before setting field values.

Sub RFC_DEEP_TABLE()
  Dim sapConn As Object
  Set sapConn = CreateObject("SAP.Functions")

  If sapConn.Connection.Logon(0, False) <> True Then
    MsgBox "Cannot Log on to SAP"
  End If

  Dim objRfcFunc As Object
  Set objRfcFunc = sapConn.Add("STFC_DEEP_TABLE")

  Set import_tab = objRfcFunc.Tables("IMPORT_TAB")
  import_tab.freetable
  import_tab.appendrow
  import_tab.cell("STR", 1) = "X"

  If objRfcFunc.Call = False Then
    MsgBox objRfcFunc.Exception
  End If

End Sub

I'm not completely sure about the line assigning the value, the parameters of the cell method should be right, but I only found a couple of slightly contradictory blog and forum posts and I'm not absolutely sure the order of the parameters is correct.

Upvotes: 0

Related Questions