Topic group Related topics Example
Hides records based on a logical condition.
SET FILTER TO [<condition>]
The condition that records must meet to be seen.
A filter is a mechanism by which you can temporarily hide, or filter out, those records that do not match certain criteria so that you can see only those records that do match. The criteria is expressed as a logical expression, for example,
set filter to upper( FIRST_NAME ) == "WALDO"
In this case, you would see only those records in the current table whose First_name field was "Waldo" (capitalized in any way).
The filter does not take effect until some sort of record navigation is attempted. For example, any command with an ALL scope will attempt to start at the first record. In this case, the command will start at the first record that matches the filter condition, and process all matching records. A SKIP command would attempt to navigate to the next matching record, and SKIP -1 would attempt to navigate to the previous matching record. GO TOP is often used after SET FILTER to position the record pointer on the first matching record.
Any time you attempt to navigate to a record, the record is evaluated to see if it matches the filter condition. If it does, then the record pointer is allowed to position itself at that record and the record can be seen. If the record does not match the filter condition, the record pointer continues in the direction it was moving to find the next matching record. It will continue to move in that direction until it finds a match or reaches end-of-file. For example, suppose you issue:
If no filter is active, you would move four records forward. If a filter is active, the records pointer will move forward until it has encountered four records that match the filter condition, and stop at the fourth. That may be the next four records in the table, if they all happen to match, or the next five, or the next 400, or never, if there arenít four records after the current record that match. In that last case, the record pointer will be at the end-of-file.
In other words, when there is no filter active, every record is considered a match. By setting a filter, you filter out all the records that donít match certain criteria.
You cannot use the special variables this or form in the <condition>. This is explicitly prohibited because these special variables automatically take on the value of whatever object and form has focus (or fires an event) at any given moment. Therefore, the filter condition will vary and quite likely be invalid. Generally speaking, you should not use variables in a filter condition at all, because the variables may go out of scope, making the filter condition an invalid expression. To solve these problems, use macro substitution, as shown in the example.
Many commands have scope option that includes FOR and WHILE conditions. These conditions are applied in addition to the filter condition.
SET FILTER applies to the current work area. Each work area may have its own filter condition. To disable the filter condition, issue SET FILTER TO with no options.
Use the rowset objectís beginFilter(†) and applyFilter(†) methods.