1

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 COMPANYCODE, GLACCT and RETURN parameters.

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
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
mrg1968
  • 11
  • 1
  • 5
  • The problem was solved, please take a look at this thread ... http://sap.ittoolbox.com/groups/technical-functional/sap-dev/sap-rfc-call-returns-error-in-return-parameter-from-vb-before-the-rfc-call-4894968#M4902486 – mrg1968 Aug 24 '12 at 10:39

1 Answers1

1

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.

Smigs
  • 2,362
  • 1
  • 21
  • 24
  • Thanks, Smigs. I'm actually not able to log on into SAP - it is a problem with the SAP server, I suppose. I'll check your suggestione as soon as I can test it ... – mrg1968 Aug 13 '12 at 16:25
  • Hi again. Tried to set the RETURN object before the call of the RFC but nothing changes, I get again 'Error 0' in the object. `objRfcFunc.Exports("COMPANYCODE") = "C100" objRfcFunc.Exports("GLACCT") = "0000000001" 'Inesistente Dim objReturn As Object Set objReturn = objRfcFunc.Imports("RETURN")` – mrg1968 Aug 15 '12 at 14:08
  • This can be useful: now I'm getting the 'Error 0' message in the moment I assign the object, before the RFC call! The error is in the code `Set objReturn = objRfcFunc.Imports("RETURN")` but it is really weird because the `BAPI_GL_ACC_EXISTENCECHECK` really returns a RETURN object of type BAPIRETURN, I checked in the SAP documentation! – mrg1968 Aug 15 '12 at 14:20