Skip to main content

Recordset Filtering

Filters are conditional expressions contained within the parentheses following the Dataset or Record Set name. Multiple filter conditions may be specified by separating each filter expression with a comma (,). All filter conditions separated by commas must be TRUE for a record to be included, which makes the comma an implicit AND operator (see Logical Operators) in this context only.

MyRecordSet := Person(per_last_name >= 'T', per_last_name < 'U');
     // MyRecordSet contains people whose last name begins with "T"
     // the comma is an implicit AND while also functioning as
     // an expression separator (implicit parentheses)


MyRecordSet := Person(per_last_name >= 'T' AND per_last_name < 'U');
// exactly the same logical expression as above

RateGE7trds := Trades(trd_rate >= '7');

ValidTrades := Trades(NOT rmsTrade.Mortgage AND
                      NOT rmsTrade.HasNarrative(rmsTrade.snClosed));

Boolean definitions should be used as recordset filters for maximum flexibility, readability and re-usability instead of hard-coding in a Record Set definition. For example, use:

IsRevolv := trades.trd_type = 'R'
                OR (~ValidType(trades.trd_type)
                   AND trades.trd_acct[1] IN ['4','5','6']);
       
isBank := trades.trd_ind_code IN SetBankIndCodes;

IsBankCard := IsBank AND IsRevolv;

WithinDate(INTEGER1 months) := ValidDate(trades.trd_drpt) AND
                               trades.trd_drpt_mos <= months;

BankCardTrades := trades(isBankCard AND WithinDate(6));

instead of:

BankCardTrades := trades(trades.trd_ind_code IN SetBankIndCodes,
                                         (trades.trd_type = 'R' OR
                                         (~ValidType(trades.trd_type) AND
                                         trades.trd_acct[1] IN ['4', '5', '6'])),
                                         ValidDate(trades.trd_drpt),
                                         trades.trd_drpt_mos <= 6);

Commas used to separate filter conditions in a recordset filter definition act as both an implicit AND operation and a set of parentheses around the individual filters being separated. This results in a tighter binding than if AND is used instead of a comma without parentheses. For example, the filter expression in this definition::

BankMortTrades := trades(isBankCard OR isMortgage, isOpen);

is evaluated as if it were written:

(isBankCard OR isMortgage) AND isOpen

and not as:

isBankCard OR isMortgage AND isOpen