MAP(expression => value, [ expression => value, ... ] [, elsevalue ] )

expressionA conditional expression.
=>The "results in" operator--valid only in MAP, CASE, and CHOOSESETS.
valueThe value to return if the expression is true. This may be a single value expression, a set of values, a DATASET, a DICTIONARY, a record set, or an action.
elsevalueOptional. The value to return if all expressions are false. This may be a single value expression, a set of values, a record set, or an action. May be omitted if all return values are actions (the default would then be no action), or all return values are record sets (the default would then be an empty record set).
Return:MAP returns a single value.

The MAP function evaluates the list of expressions and returns the value associated with the first true expression. If none of them match, the elsevalue is returned. MAP may be thought of as an "IF ... ELSIF ... ELSIF ... ELSE" type of structure.

All return value and elsevalue values must be of exactly the same type or a "type mismatch" error will occur. All expressions must reference the same level of dataset scoping, else an "invalid scope" error will occur. Therefore, all expressions must either reference fields in the same dataset or the existence of a set of related child records (see EXISTS).

The expressions are typically evaluated in the order in which they appear, but if all the return values are scalar, the code optimizer may change that order.


Attr01 := MAP(EXISTS(Person(Person.EyeColor = 'Blue')) => 1,
              EXISTS(Person(Person.Haircolor = 'Brown')) => 2,
 //If there are any blue-eyed people, Attr01 gets 1
 //elsif there any brown-haired people, Attr01 gets 2
 //else, Attr01 gets 3

Valu6012 := MAP(NoTrades => 99,
                NoValidTrades => 98,
                NoValidDates => 96,
 //If there are no trades, Valu6012 gets 99
 //elsif there are no valid trades, Valu6012 gets 98
 //elsif there are no valid dates, Valu6012 gets 96
 //else, Valu6012 gets Count6012

MyTrades := MAP(rms.rms14 >= 93 => trades(trd_bal >= 10000),
                rms.rms14 >=  2 => trades(trd_bal >= 2000),
                rms.rms14 >=  1 => trades(trd_bal >= 1000),
 // this example takes the value of rms.rms14 and returns a 
 // set of trades based on that value. If the value is <= 0,
 // then all trades are returned.