on 08-19-2013 3:28 PM
I use a VBA program to connect to an SAP system and to execute a FM. The function module has the following interface:
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(I_RNG_ZSNR) TYPE /GKV/BP01_TAB_RNG_ZSNR
*" EXPORTING
*" VALUE(E_TAB_FKZS) TYPE /GKV/BP01_TAB_D_FKZS
*"----------------------------------------------------------------------
The importing parameter is a table of a structure:
What is the correct way to set the export parameter I_RNG_ZSNR?
Here my VBA code:
Option Explicit
Sub Test()
Dim Func As SAPFunctions
Dim Conn As SAPLogonCtrl.Connection
Dim f As SAPFunctionsOCX.Function
Dim X As Object
Dim row As Object
Dim Ret As Long
Set Func = CreateObject("SAP.Functions.Unicode")
If IsObject(Func) Then
Set Conn = Func.Connection
Conn.Client = "001"
Conn.User = "BCUSER"
Conn.Language = "EN"
Conn.HostName = "NSP"
Conn.SystemNumber = 0
If Not Conn.Logon(0, False) Then
Debug.Print "Connection not successful"
Else
Debug.Print "Connection successful"
Set f = Func.Add("/GKV/BP01_K_FKZS_MASS_READ")
If IsObject(f) Then
Set X = f.Exports("I_RNG_ZSNR")
Set row = X.AppendRow
'Error: Object doesn't support this property or method
'It not seems to be a table
row.Cell(1, "SIGN") = "I"
row.Cell(1, "OPTION") = "EQ"
row.Cell(1, "LOW") = "10600035"
Ret = f.Call
End If
Conn.Logoff
End If
Set Func = Nothing
End If
End Sub
With COMConnector (CCo) it works perfect:
Option Explicit
Sub CCoTest()
'-Variables-----------------------------------------------------------
Dim SAP As CCo.COMNWRFC
Dim hRFC As Long
Dim rc As Integer
Dim hFunc As Long
Dim hFuncDesc As Long
Dim hTable As Long
Dim hRow As Long
Dim hExpTable As Long
Dim i, RowCount As Long
Dim charBuffer As String
Set SAP = CreateObject("COMNWRFC")
If IsObject(SAP) Then
hRFC = SAP.RFCOPENCONNECTION("ASHOST=NSP, SYSNR=00, " & _
"CLIENT=001, USER=BCUSER")
If hRFC Then
hFuncDesc = SAP.RFCGETFUNCTIONDESC(hRFC, "/GKV/BP01_K_FKZS_MASS_READ")
If hFuncDesc Then
hFunc = SAP.RFCCREATEFUNCTION(hFuncDesc)
If hFunc Then
SAP.RFCGETTABLE hFunc, "I_RNG_ZSNR", hTable
If hTable Then
hRow = SAP.RFCAPPENDNEWROW(hTable)
SAP.RFCSETCHARS hRow, "SIGN", "I"
SAP.RFCSETCHARS hRow, "OPTION", "EQ"
SAP.RFCSETCHARS hRow, "LOW", "10600035"
If SAP.RFCINVOKE(hRFC, hFunc) = RFC_OK Then
SAP.RFCGETTABLE hFunc, "E_TAB_FKZS", hExpTable
If hExpTable Then
SAP.RFCGETROWCOUNT hExpTable, RowCount
SAP.RFCMOVETOFIRSTROW hExpTable
For i = 1 To RowCount
hRow = SAP.RFCGETCURRENTROW(hExpTable)
charBuffer = Space(512)
SAP.RFCGETCHARS hRow, "NAME1", charBuffer, 512
Debug.Print charBuffer
If i < RowCount Then
SAP.RFCMOVETONEXTROW hExpTable
End If
Next
End If
End If
End If
rc = SAP.RFCDESTROYFUNCTION(hFunc)
End If
End If
rc = SAP.RFCCLOSECONNECTION(hRFC)
End If
Set SAP = Nothing
End If
End Sub
How can I set the export parameter with SAP ActiveX control?
Thanks for tips and hints.
Hello Tang,
thank you very much for your reply and your test result.
So the only way I see seems to be via COMConnector (CCo).
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I’ve had success by allowing VBA to provide structure through return fro SAP.Function call.
Use listobject type variable to hold the range table inputs.
where list object is established similar to how you used cell addresses. Just define that cell range as a ListObject.
Set rngTab = func.exports(function export park name)
Good lick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mark, Can you porvide the code you used?
Hello Tang,
not yet, unfortunately.
Do you try the suggestion of Seby from the post Dec. 12 2013?
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan,
My earlier suggestion would probably have worked on import parameters being returned. I think that in your case, as the exported parameter is a structure, we need to create it with correct structure using the connection object method before using it.
Dim X as Object
Set X = Conn.CreateStructure("/GKV/BP01_TAB_RNG_ZSNR")
X("SIGN") = "I"
X("OPTION") = "EQ"
X("LOW") = "10600035"
X("HIGH") = ""
...
Check this option once and let me know.
Regards,
Seby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Seby,
thanks for your reply. With your code I get the following error message:
FunctionsCtrl::SetupConnection found R/3 release731
FunctionsCtrl::CreateDefFunctions() Starting ...
CreateDefFunctions: Making tables.
MakeTable (pn=FIELDS tn=RFC_FIELDS)
MakeTable (pn=PARAMS tn=RFC_FUNINT)
FunctionsCtrl::CreateDefFunctions() - Finished.
Packing Parameters for RFC_SYSTEM_INFO Packing structure RFCSI_EXPORT.
Calling RFC Function 'RFC_SYSTEM_INFO'
RFC CALL status = RFC_OK
Importing 1 parameters:
Structure: Type= 'RFC_FUNINT'.
PARAMETER: 'E_TAB_FKZS02'; PARAMCLASS: 'E'
FIELDNAME: ' '; TABNAME: '/GKV/BP01_TAB_C_FKZS02'
Creating Structure table name = /GKV/BP01_TAB_C_FKZS02 parameter = E_TAB_FKZS02
Structure::Create name= E_TAB_FKZS02 parameter name = E_TAB_FKZS02
PARAMETER: 'I_RNG_ZSNR'; PARAMCLASS: 'I'
FIELDNAME: ' '; TABNAME: '/GKV/BP01_TAB_RNG_ZSNR'
Creating Structure table name = /GKV/BP01_TAB_RNG_ZSNR parameter = I_RNG_ZSNR
Structure::Create name= I_RNG_ZSNR parameter name = I_RNG_ZSNR
FunctionsCtrl::AddItem succeeds: /GKV/BP01_K_FKZS_MASS_READ
Packing Parameters for /GKV/BP01_K_FKZS_MASS_READ
Packing structure E_TAB_FKZS02.
Packing structure I_RNG_ZSNR.
Calling RFC Function '/GKV/BP01_K_FKZS_MASS_READ'
RFC CALL status = RFC_SYS_EXCEPTION
RFC Error: 002CE958
-Status:002CE99A
-Message:002CEA9A
-Internal Status:002CEC9A
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan,
You should be using the value property of export parameter structure with the appropriate index - the column position. So it should be like:
Set X = f.Exports("I_RNG_ZSNR")
X.Value(1) = "I" ' SIGN
X.Value(2) = "EQ" ' OPTION
X.Value(3) = "10600035" ' LOW
Ret = f.Call
Reading the imported structures also can be done the same way. I am not sure whether named references like X.Value("SIGN") will work. You can try it out and let us know.
Regards,
Seby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.