on 12-22-2013 8:21 PM
Hello,
I try to fetch some data from our SAP ERP system by using a customer specific function module.
The connection via RFC is working. Unfortunately, after trying to add the SAP function module to the connection, the result is still nothing.
I have a VBA function for the connection. The return value of this function is the working connectin to SAP system.
Private Function sapConnect() As Object
'---------------------------------------------------------------------------------------
' Procedure : sapConnect
' Author : Steffen Retz
' Date : 22.11.2013
' Purpose :
'---------------------------------------------------------------------------------------
'
Dim sapConnection As Object
Dim sapFunction As Object
Dim RetVal As Variant
Dim ME5 As Variant
Dim strSAP_System As String
On Error GoTo sapConnect_Error
'Set sapConnect = False
Set sapFunction = CreateObject("SAP.Functions")
Set sapConnection = sapFunction.Connection
With sapConnection
.ApplicationServer = "xx.xxx.xx.xx"
.SystemNumber = xxx
.System = "xxx"
.client = "xxx"
.Language = "EN"
.User = m_strcUserName 'InputBox("Please insert your SAP user name", "SAP Connection: User")
'.Password = InputBox("Please insert you SAP password", "SAP Connection: Password")
RetVal = SysCmd(acSysCmdSetStatus, "Connecting to " & strSAP_System & " . . . ")
If .logon(0, True) <> True Then
If .logon(0, False) <> True Then
'No connection -> Error
.LastError
Exit Function
End If
Set sapConnect = sapFunction
End If
End With
sapConnect_Exit:
On Error Resume Next
Exit Function
sapConnect_Error:
Err.Number = vbObjectError + 1
Err.Source = m_strcClassName
Err.Description = "Error" & " <<>> " & Err.Description
LogError Err, Critical, "sapConnect"
GoTo sapConnect_Exit
On Error GoTo 0
End Function
The other function is using the returning connection to retrieve the data from the SAP system.
After adding the function module to the connection, I recognized that the object MyFunc is still empty.
Set MyFunc = R3.Add("Z_ZZMHP_HR_SAP_NOTES_READ")
I also tried this with RFC_READ_TABLE and BAPI_USER_GETLIST. Both functions are working.
Private Function RFC_SAP_NOTES_READ(sapConnection As Object, arrSAPNotes As Variant) As Boolean
'---------------------------------------------------------------------------------------
' Procedure : RFC_SAP_NOTES_READ
' Author : Steffen Retz
' Date : 03.12.2013
' Purpose : FM in SAP: Z_ZZMHP_HR_SAP_NOTES_READ
'---------------------------------------------------------------------------------------
'
Dim strTemp As String
Dim RetVal As Variant, nSecondsLeft As Long, nTotalSeconds As Long
Dim R3, MyFunc, App As Object
Dim j As Integer
' Define the objects to hold IMPORT parameters
Dim IT_SAP_NOTES_KEY As Object
' Define the objects to hold the EXPORT parameters
Dim ZZMHP_TT_HR_SAP_NOTES_ERRORMSG As Object
Dim ET_SAP_NOTES As Object
' Use to write out results
Dim ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow, iField, iLength As Integer
On Error GoTo RFC_SAP_NOTES_READ_Error
If sapConnection Is Nothing Then
Set R3 = sapConnect
Else
Set R3 = sapConnection
End If
'*****************************************************
'Call RFC function Z_ZZMHP_HR_SAP_NOTES_READ
'*****************************************************
Set MyFunc = R3.Add("Z_ZZMHP_HR_SAP_NOTES_READ")
'EXPORTS
Set IT_SAP_NOTES_KEY = MyFunc.exports("IT_SAP_NOTE_KEY")
IT_SAP_NOTES_KEY.Value = arrSAPNotes
'IMPORTS
Set ZZMHP_TT_HR_SAP_NOTES_ERRORMSG = MyFunc.imports("ZZMHP_TT_HR_SAP_NOTES_ERRORMSG")
Set ET_SAP_NOTES = MyFunc.imports("ET_SAP_NOTES")
RetVal = SysCmd(acSysCmdSetStatus, "Extracting " & j & " . . . ")
MyFunc.Call
' Result = MyFunc.Call
' If Result = True Then
' Set DATA = MyFunc.Tables("DATA")
' Set FIELDS = MyFunc.Tables("FIELDS")
' Set OPTIONS = MyFunc.Tables("OPTIONS")
' Else
' MsgBox MyFunc.EXCEPTION
' R3.Connection.LOGOFF
' Exit Function
' End If
Close #2
RetVal = SysCmd(acSysCmdRemoveMeter)
RFC_SAP_NOTES_READ = True
RFC_SAP_NOTES_READ_Exit:
On Error Resume Next
Exit Function
RFC_SAP_NOTES_READ_Error:
RFC_SAP_NOTES_READ = False
Err.Number = vbObjectError + 1
Err.Source = m_strcClassName
Err.Description = "Error" & " <<>> " & Err.Description
Debug.Print Err.Description
LogError Err, Critical, "RFC_READ_TABLE"
GoTo RFC_SAP_NOTES_READ_Exit
On Error GoTo 0
End Function
I can't find the error. Do I have to use a specific method for a customer specific fuction module?
Or is it not possible to use a customer specific function module?
Thanks for any help.
Best regards,
Steffen
Hello.
Late, but maybe not too late 🙂
Is your customized functionmodule RFC-enabled?
Best regards,
Holger
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.