Trying to do a RFC-call to SAP from VBA

Hermanito

Well-known Member
Joined
Apr 4, 2007
Messages
1,238
Hi all,

does anyone here have any experience with Remote Function Calls from VBA to SAP? I'm trying to automate pulling data from SAP into Excel. Our SAP-installation has some RFC functions available and I'm trying to adapt some code samples found on the net to work in our situation, but no luck so far :-(

Connecting and logging on to SAP works... but then the trouble starts... I have no real understanding of how to make a RFC-call work...

Some of the code I have now:
Code:
Set LogonControl = CreateObject("SAP.LogonControl.1")
Set FuncControl = CreateObject("SAP.Functions")
Set Conn = LogonControl.NewConnection
Conn.System = "ZZZ"
Conn.client = "111"
Conn.Language = "EN"
Conn.user = "username"
Conn.Password = "password"
retcd = Conn.Logon(0, False)
If retcd <> True Then
    MsgBox " Cannot log on! "
    MsgBox retcd
    Stop
Else
    MsgBox " Logon OK."
End If

FuncControl.Connection = Conn    'ERROR HERE: Internal Application Error 61704

 Const attachpath = "C:\Query.CSV"
 Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")
 Set filOutput = objFileSystemObject.CreateTextFile(attachpath, True)
Set RFC_READ_TABLE = FuncControl.Add("ZZZ_BOM")
     Set strExport1 = ZZZ_BOM.Exports("QUERY_TABLE")
     Set strExport2 = ZZZ_BOM.Exports("DELIMITER")
     Set tblOptions = ZZZ_BOM.Tables("OPTIONS")
     Set tblData = ZZZ_BOM.Tables("BOM_DOWNL_01")
     Set tblFields = ZZZ_BOM.Tables("FIELDS")
The ZZZ_BOM is the RFC function in our system...

I'd be happy with any advice, tips, pointers to good info...
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Thanks for your reply.
I had found that same page already when searching, it looks interesting, but I have not tried it, because I don't have the same Controls he uses in his example. I will take a second look at the code snippets, but I'm afraid it will not get me where I want to be...
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top