简体   繁体   中英

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

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

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

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.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM