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:
The ZZZ_BOM is the RFC function in our system...
I'd be happy with any advice, tips, pointers to good info...
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")
I'd be happy with any advice, tips, pointers to good info...