SAP RFC call returns "Error 0" in RETURN parameter from vb

mrg1968 picture mrg1968 · Aug 7, 2012 · Viewed 8.4k times · Source

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 objReturn object/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.

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 ...).

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

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

Answer

Smigs picture Smigs · Aug 9, 2012

You need to put

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

BEFORE 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.