简体   繁体   English

SAP RFC调用从vb的RETURN参数中返回“错误0”

[英]SAP RFC call returns “Error 0” in RETURN parameter from vb

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. 我正在尝试从vb使用RFC调用SAP BAPI,但在获取调用结果时遇到了一些问题。 The BAPI "BAPI_GL_ACC_EXISTENCECHECK" (from General Ledger Account module) has two parameters, COMPANYCODE and GLACCT, and a RETURN parameter. BAPI“ BAPI_GL_ACC_EXISTENCECHECK”(来自“总帐帐户”模块)具有两个参数:COMPANYCODE和GLACCT,以及一个RETURN参数。 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. 我编写了这段代码来进行调用,而建立SAP连接没有问题(我使用SAP登录控制OLE / COM对象来完成此工作),并且尝试进行RFC调用。
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. 同样在这种情况下,我进行调用没有问题(似乎不确定),因为RFC调用返回true且没有异常。
However, looking through the objReturn object/parameter, it has a value "Error 0" in it. 但是,查看objReturn对象/参数时,它的值为“错误0”。 I was expecting a complex structure like the BAPIRETURN object in SAP or something similar if the account doesn't exist. 我期待的是一个复杂的结构,例如SAP中的BAPIRETURN对象,或者如果该帐户不存在,则类似的结构。

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

You need to put 你需要放

Dim objReturn As Object
Set objReturn = objRfcFunc.imports("RETURN")

BEFORE objRfcFunc.Call objRfcFunc.Call之前

ie you must state what you're importing from the function before you call it. 也就是说,您必须先声明要从函数中导入的内容,然后才能调用它。 I usually put it alongside the .exports() lines. 我通常将其放在.exports()行旁边。

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

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