CaseStatement
The Case statement performs logic similar to an IF or Switch statement but is typically easier to read and maintain. Depending on the value of an element or expression, control is transferred to the first matching when clause.
Syntax:
Case on <variable>
when <value> then <result>
[when <value> then <result>]
[else <result>]
endRemarks:
- The
on <variable>portion in the syntax may be omitted when the conditions in thewhenclauses are complete expressions (see examples).
Examples:
The examples provided below are based on fictitious data for illustrative purposes only.
>Example 1: Evaluating the Boolean value of an expression
Formula:
flag_check := False;
return :=
Case
when flag_check then "Flag is True"
else "Flag is False"
end;Result:
| Flag is False |
>Example 2: Evaluating a single condition
Formula:
Entity := "5010";
return :=
Case
when Entity = "5000" then "ABC Insurance Company"
when Entity = "5010" then "QQQ Retirement Fund"
else "Unknown entity"
end;Result:
| QQQ Retirement Fund |
>Example 3: Evaluating multiple conditions
Formula:
Entity := "5010";
TimeSeries := "EPS";
return :=
Case
when Entity = "5010" & TimeSeries = "Price" then "MarketDataProvider1"
when Entity = "5010" & TimeSeries = "EPS" then "StockExchange1"
else "PortfolioAdministrator1"
end;Result:
| StockExchange1 |
