2

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
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
user3213199
  • 21
  • 1
  • 2

2 Answers2

0

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.

Dirk Trilsbeek
  • 5,873
  • 2
  • 25
  • 23
  • Hi Dirk, Thank you for your answer. Unfortunately, this does not work. The same error appears at the line "Set import_tab = objRfcFun.Tables("IMPORT_TAB")". Best regards – user3213199 Oct 23 '17 at 06:51
  • yes, it seems like this is a problem with the function you want to call. I've seen the same error here, but other RFC functions, for instance RFC_READ_TABLE, do work. Debugging showed that the code fails to even create the object objRfcFunc. My guess is the deep structure used in the function module isn't supported in the classic RFC library. It might just be a bug, but I've tested two different SAP GUI releases and both had the same problem, so it might be by design. – Dirk Trilsbeek Oct 23 '17 at 10:27
0

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"