ViewManager.SetFilter - Make it easy, use equates

In the docs and over the years, I’ve seen several examples with ABC SetFilter method calls such as:
BRWxx.SetFilter(‘My Filter String’,‘1-ID’)
BRWxx.SetFilter(‘My Filter String’,‘9-ID’)

Often forgotten with this code is the documented sorting of the ID priority parameter - “highest number first, lowest number last.” This says, confusingly enough in my mind, that the 2nd example above has priority.

In order to forever forget these documented details, every developer should define a set of their own ID priority equates that is most meaningful to them and include the set at the global level. Not only is it good to banish the single quotes but my head insists that #1 must be top priority. Here is the set I use:
FILTER:1 EQUATE(‘9’)
FILTER:2 EQUATE(‘8’)

FILTER:8 EQUATE(‘2’)
FILTER:9 EQUATE(‘1’)

Re-written, here is initial example:
BRWxx.SetFilter(‘My Filter String’,FILTER:1)
BRWxx.SetFilter(‘My Filter String’,FILTER:2)

2 Likes

Remember, in a SQL environment the priority is meaningless. All of the SetFilter values get translated into the WHERE clause. The SQL engine will develop the execution plan based on its statistics. The order of the clauses in the WHERE do not influence the optimizations made.
In that case the SetFilter with the extra name parameter is just useful to keep things organized in your code and allow multiple calls to SetFilter.

A good reminder, Rick. I will admit to every once in awhile still not trusting the Postgres optimizer 100%. Though one might prefer to use CHOOSE, one simple example of multiple SetFilter calls within the MyBrowse.ApplyFilter method (also uses other common equate):

IF MyQueryValue = eZero
SELF.SetFilter(eNil,FILTER:2)
ELSE
SELF.SetFilter(‘Tbl:Field=’ & MyQueryValue,FILTER:2)
END