Created
February 16, 2012 02:45
-
-
Save kubrick06010/1841195 to your computer and use it in GitHub Desktop.
read tables via SAP RFC connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'Para iniciar la conexion debes añadir las referencias activex (ficheros .ocx) que correspondan | |
| Dim objFileSystemObject As Object | |
| Dim ctlLogon As Object | |
| Dim ctlTableFactory As Object | |
| Dim objWindowsScriptShell As Object | |
| Dim objConnection As Object | |
| Dim conn As Object | |
| Set objFileSystemObject = CreateObject("Scripting.FileSystemObject") | |
| Set ctlLogon = CreateObject("SAP.LogonControl.1") | |
| Set funcControl = CreateObject("SAP.Functions") | |
| Set ctlTableFactory = CreateObject("SAP.TableFactory.1") | |
| Set objWindowsScriptShell = CreateObject("WScript.Shell") | |
| Set objConnection = ctlLogon.NewConnection | |
| 'Set filOutput = objFileSystemObject.CreateTextFile(attachpath, True) | |
| Set conn = funcControl.Connection | |
| With objConnection | |
| .ApplicationServer = "127.0.0.1" | |
| .System = "PR" | |
| .SystemNumber = "01" | |
| .User = "" | |
| .Password = "" | |
| .client = "007" | |
| .language = "E" | |
| 'conn.systemid = "" | |
| .tracelevel = 0 | |
| .usesaplogonini = False | |
| End With | |
| objConnection.RFCWithDialog = True | |
| If objConnection.Logon(0, False) <> True Then | |
| MsgBox "Conexion Exitosa!" | |
| Set getSapConnection = Nothing | |
| Exit Function | |
| End If | |
| Set getSapConnection = objConnection | |
| End Function | |
| 'Luego exportamos las variables: | |
| Set RFC_READ_TABLE = funcControl.Add("RFC_READ_TABLE") | |
| Set strExport1 = RFC_READ_TABLE.Exports("QUERY_TABLE") | |
| Set strExport2 = RFC_READ_TABLE.Exports("DELIMITER") | |
| Set tblOptions = RFC_READ_TABLE.Tables("OPTIONS") | |
| Set tblData = RFC_READ_TABLE.Tables("DATA") | |
| Set tblFields = RFC_READ_TABLE.Tables("FIELDS") | |
| strExport1.Value = "EBAN" | |
| StrExport2.Value = "," | |
| 'Se definen los campos requeridos para el query segun tblFields | |
| 'Se ejecuta la llamada | |
| 'Luego se extraen y manipulan los datos obtenidos en tblData |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Código