简体   繁体   English

VBA to SAP // RFC 功能模块,以表为输入参​​数

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

I want to send data from Excel via a RFC-Connector to SAP.我想通过 RFC 连接器将数据从 Excel 发送到 SAP。

For the RFC function module, I must fill a table as an input parameter.对于RFC功能模块,我必须填写一个表格作为输入参数。 Comparable to the RFC function module STFC_DEEP_TABLE .与 RFC 功能模块STFC_DEEP_TABLE

My VBA code stops at the with statement with the error:我的 VBA 代码在 with 语句处停止并出现错误:

“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.我无法对此进行测试,但是通过阅读 VBA/SAP Net Connector,您似乎类似于 C# 的 .Net Connector 语法,必须在设置字段值之前向导入表中添加一行。

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.我不完全确定分配值的行, cell方法的参数应该是正确的,但我只发现了几个稍微矛盾的博客和论坛帖子,我不确定参数的顺序是否正确.

I had the same problem, that I could not instantiate the BAPI.我遇到了同样的问题,我无法实例化 BAPI。 The SAP guys altered the BAPI, and I could access it without altering the code. SAP 人员更改了 BAPI,我可以在不更改代码的情况下访问它。
BTW: the parameter order is: BTW:参数顺序是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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