on 09-09-2014 3:08 AM
Hi,
I am trying to set the filters in my workbook using VBA code. I am using the code below, however, the SAPSetFilter call returns a result of 0 (i.e. fails). The technical name is correct and the value is valid. I can get the SAPSetVariable call to work correctly for the fields that are prompts. I have tried many searches but do not seem to be able to work it out.
Any help would be greatly appreciated.
Regards
Lachlan
dataSourceAlias = Application.Run("SAPGetCellInfo", Excel.ActiveWorkbook.Sheets("InventoryData").Cells(1, 1), "DATASOURCE")
lResult = Application.Run("SAPSetRefreshBehaviour", "Off")
lResult = Application.Run("SAPExecuteCommand", "PauseVariableSubmit", "On")
lResult = Application.Run("SAPSetVariable", "Calendar Month/Year From", "01.2014", "INPUT_STRING", dataSourceAlias)
lResult = Application.Run("SAPSetVariable", "Calendar Month/Year TO", "08.2014", "INPUT_STRING", dataSourceAlias)
PlantSel = "1000"
lResult = Application.Run("SAPSetVariable", "Plant (Selection Options, Optional)", PlantSel, "INPUT_STRING", "DS_1")
'''''''''''''''''All above code works ok''''''''''''''
''''''''''''''''the line below returns a value of 0'''''''''''''''''''''
lResult = Application.Run("SAPSetFilter", dataSourceAlias, "0MATERIAL", "200", "KEY")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
lResult = Application.Run("SAPExecuteCommand", "PauseVariableSubmit", "Off")
lResult = Application.Run("SAPSetRefreshBehaviour", "On")
Hi Lachlan,
on the first glance I can't see the Problem either...
You could use this coding, to check the error message:
Example (you can replace "DS_1"):
Dim lResult As Variant
Dim lError As Variant
lResult = Application.Run("SAPExecuteCommand", "Refresh", "DS_1")
lError = Application.Run("SAPGetProperty", "LastError")
If lError(1) <> 0 Then
'an error occured, display the code and text of it
lMsg = Application.Run("SAPAddMessage", "Error: " & lError(1) & " " & lError(2), "ERROR")
Else
lResult = Application.Run("SAPExecuteCommand", "ShowPrompts", "DS_1")
End If
Just replace the Refresh by your SAPSetFilter.
Btw.: You should include always the coding part to refresh your datasource, before you set any filter or variable!
Best regards,
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Martin,
Thanks for your assistance.
I ran your code, and the SAPSetFilter command actually worked. It was the same as my other code except I was the following line
lResult = Application.Run("SAPExecuteCommand", "PauseVariableSubmit", "On")
When I remove this line from the code above the SAPSetFilter command works. My understanding of this line was that it just stopped the workbook from refreshing the filters hence allowing multiple filters to be changed before refreshing the data. It seems this is not the case.
Any comments appreciated.
Thanks
Lachlan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.