cancel
Showing results for 
Search instead for 
Did you mean: 

Calling RFC from VB

Former Member
0 Kudos

Hi,

I'm trying to call an RFC enabled function module from excel. My code in VB is:


    Set theFunc = sapConn.Add("ZGETREVENUE")

    theFunc.Exports("VBELN") = strSalesOrder
    ResultsOk = theFunc.imports("OK_CODE")
    Set objSalesOrder = theFunc.Tables("TBL_RETURN")

The table TBL_RETURN is coming back fine but the return code OK_CODE is always 0. Can someone point out what I'm doing wrong?

Thanks,

Gill

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

The guy who wrote it fixed the code. He wasn't calling the RFC before checking the return code.

0 Kudos

Hello Gill

Try calling theFunc.Call function before calling theFunc.imports.

theFunc.Call will execute the function module.

Regards,

Dinesh

michael_hobbins
Active Participant
0 Kudos

Sorry Gill, Dinesh is right.

The call method returns a true/false condition (true indicates a correct execution)

The code should look something like

Set theFunc = sapConn.Add("ZGETREVENUE")

theFunc.Exports("VBELN") = strSalesOrder

If theFunc.Call Then
   ResultsOk = theFunc.imports("OK_CODE")
   Set objSalesOrder = theFunc.Tables("TBL_RETURN")
else
   msgbox "Call error"
end if

Cheers,

Michael

michael_hobbins
Active Participant
0 Kudos

Hello Gill, can you post your RFC's code? There doesn't seem to be anything wrong with your VB code

Cheers

Michael