cancel
Showing results for 
Search instead for 
Did you mean: 

Instantiating a RFC BAPI using VBA (Excel)

09-16-2022 9:42 PM
2820 views 6 comments
0 Likes
SAP Managed Tags
Subscribe

I have been able to successfully log onto SAP from inside excel and have a BAPI I'm trying to call. This BAPI takes a single parameter. But I'm trying to figure out how to instantiate the BAPI (using 64-bit controls). Honestly, just looking for the next step after logging on (which I've been able to do using SAPLogonCtrl.

Current Code that is working and the three attempts I've made all failing (commented out all the failed code) 🙂

Dim sapLogon As SAPLogonCtrl.SAPLogonControl
Dim sapConn As SAPLogonCtrl.Connection
Set sapLogon = New SAPLogonControl
Set sapConn = sapLogon.NewConnection
With sapConn
.System = "ED1"
.ApplicationServer = "{serverName}"
.SystemNumber = "{serverNumber}" '
.Client = "{clientNumber}"
.User = "user"
.Password = "userPasword"
.Language = "EN"
End With
Call sapConn.Logon(0, True)
If sapConn.IsConnected <> tloRfcConnected Then
MsgBox "connection failed. " & sapConn.IsConnected
Exit Sub
Else
MsgBox "Connection Successful!!! - Code " & sapConn.IsConnected '<- this line runs!!!!
End If
'NOTE: I CAN GET TO HERE JUST FINE WITH THE LOGON
'FIRST ATTEMPT (FAIL)
'Dim RFCFunc As New SAPFunctionsOCX.Function
'Dim SAPFunCtl As New SAPFunctions
'
'Set RFCFunc = SAPFunCtl.Add("Z_BAPI_ALM_ORDER_MAINTAIN_01")
'SECOND ATTEMPT (FAIL)
'Dim functions As Object
'Dim obSapBapi As Object
'
'Set functions = sap.functions(sapConn)
'Set obSapBapi = functions.Add("Z_BAPI_ALM_ORDER_MAINTAIN_01")
'THIRD ATTEMPT (FAIL)
'Dim oSAP As Object
'Dim objGetList As Object
'Set oSAP = sapConn.RfcCOMInstance
'Set objGetList = oSAP.Add("Z_BAPI_ALM_ORDER_MAINTAIN_01")
End Sub
0 Likes

Accepted Solutions (0)

Answers (1)

Answers (1)

Ulrich_Schmidt1
Product and Topic Expert
Product and Topic Expert
0 Likes

Hello John,

"Class not registered" sounds like a problem on Windows COM level. I am not familiar with the RFC controls/OCX used here, but I think I remember there are three or four ocx libraries. Perhaps one of them has not yet been registered as COM library?

In any case, let me also recommend a different solution: instead of the old OCX controls, have you also thought about using the .NET Connector (NCo)? It can also be used for making RFC calls from Excel or VB scripts and it has two advantages: it's up-to-date technology, and there is lots of documentation and samples. (Samples are mainly in C#, but there is also a short tutorial in VB.NET)

See https://support.sap.com/nco
Current version 3.0 is supported until Dec. 2023, but a new version 3.1 is going to be released in a couple of weeks.

Best Regards, Ulrich