vba SAP RFC 调用在来自 vb 的 RETURN 参数中返回“错误 0”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11849252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SAP RFC call returns "Error 0" in RETURN parameter from vb
提问by mrg1968
Hi everybody and thanks in advance.
大家好,提前致谢。
I'm trying to call a SAP BAPI using RFC from vb but I'm having some problem to get the result of the call.
The BAPI "BAPI_GL_ACC_EXISTENCECHECK" (from General Ledger Account module) has two parameters,
COMPANYCODE and GLACCT, and a RETURN parameter.
I wrote this piece of code to make the call and I had no problem to establish the SAP Connection (I use the SAP Logon Control OLE/COM object to do the job), and I tried to make the RFC call.
Also in this case I make the call without problems (it seems, not sure about it ...), because the RFC call returns true and no exception.
However, looking through the objReturnobject/parameter, it has a value "Error 0" in it.
I was expecting a complex structure like the BAPIRETURN object in SAP or something similar if the account doesn't exist.
我正在尝试使用 vb 中的 RFC 调用 SAP BAPI,但在获取调用结果时遇到了一些问题。BAPI“BAPI_GL_ACC_EXISTENCECHECK”(来自总帐科目模块)有两个参数,COMPANYCODE 和 GLACCT,以及一个 RETURN 参数。我编写了这段代码来进行调用,并且建立 SAP 连接没有问题(我使用 SAP 登录控制 OLE/COM 对象来完成这项工作),并且我尝试进行 RFC 调用。
同样在这种情况下,我拨打电话没有问题(似乎,不确定......),因为 RFC 调用返回 true 并且没有异常。
但是,查看objReturn对象/参数,其中包含一个值“错误 0”。
Tried to search with Google and SAP forums but I haven't found a real solution to my problem, so here I am to ask you all if you have some idea to solve this problem (maybe I'm only making a wrong call!!! I'm quite a newbie on SAP integration ...).
尝试使用 Google 和 SAP 论坛进行搜索,但我还没有找到真正解决我的问题的方法,所以在这里我想问问大家是否有解决此问题的想法(也许我只是打错了电话!! !我是 SAP 集成的新手......)。
BTW, Final Notes: after a lot of RFC_NO_AUTHORIZATION on the SAP side, they gave me a SAP_ALL / S_RFC authorization (sort of, not a SAP expert) and the error RFC_NO_AUTHORIZATION disappeared, but not the Error 0 return
顺便说一句,最终说明:在 SAP 方面进行了大量 RFC_NO_AUTHORIZATION 之后,他们给了我 SAP_ALL / S_RFC 授权(有点,不是 SAP 专家)并且错误 RFC_NO_AUTHORIZATION 消失了,但没有返回错误 0
Dim sapConn As Object
Dim objRfcFunc As Object
Dim SAPMandante As String
Dim SAPUtente As String
Dim SAPPassword As String
Dim SAPLingua As String
Dim SAPApplicationServer As String
Dim SAPNumeroSistema As Variant
Dim SAPIDSistema As String
Dim SAPRouter As String
Dim FlagInsertLogin As Integer
Dim FlagLogin As Variant
On Error GoTo ErrorHandler
Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
'Silent Logon
SAPMandante = "xxx"
SAPUtente = "yyyy"
SAPPassword = "zzzzzz"
SAPLingua = "IT"
SAPApplicationServer = "www.xxx.com"
SAPNumeroSistema = x
SAPIDSistema = "zzz"
SAPRouter = ""
FlagLogin = SilentLogin(sapConn, SAPMandante, SAPUtente, SAPPassword, SAPLingua, SAPApplicationServer, SAPNumeroSistema, SAPIDSistema, SAPRouter) 'IT WORKS, NO PROBLEM HERE
If FlagLogin = False Then
'Explicit Logon
If sapConn.Connection.logon(0, False) <> True Then
MsgBox "Cannot Log on to SAP", 16, "Query Interrupted"
sapConn.Connection.logoff
Set sapConn = Nothing
InsertCash = False
Exit Sub
End If
End If
'BAPI RFC Call
Set objRfcFunc = sapConn.Add("BAPI_GL_ACC_EXISTENCECHECK")
objRfcFunc.exports("COMPANYCODE") = "C100"
objRfcFunc.exports("GLACCT") = "0000000001" 'Inexistent
Rem *** BAPI CALL ***
If objRfcFunc.Call = False Then
ErrorMsg = objRfcFunc.Exception 'Message collection
MsgBox ErrorMsg, 16, "Errore"
sapConn.Connection.logoff
Exit Sub
else
Dim objReturn As Object
Set objReturn = objRfcFunc.imports("RETURN")
End If
采纳答案by mrg1968
The problem was solved, please take a look at this thread ...
问题已解决,请看一下这个线程...
回答by Smigs
You need to put
你需要把
Dim objReturn As Object
Set objReturn = objRfcFunc.imports("RETURN")
BEFORE objRfcFunc.Call
前 objRfcFunc.Call
i.e. you must state what you're importing from the function before you call it. I usually put it alongside the .exports()
lines.
即,在调用函数之前,您必须说明从函数中导入的内容。我通常把它放在.exports()
线条旁边。