Use a SPLASH if/then/else statement and perform the same logic using a switch statement.
The example creates a schema called TradeSchema, and an input window called TradeWindow that references the schema. The File CSV Input adapter is attached to the window.
The example then performs a SPLASH if/then/else function with nested if statements.
CREATE FLEX FlexIfThenElse IN TradeWindow OUT OUTPUT WINDOW FlexIFEOut Schema TradeSchema Primary Key (Ts)BEGIN ON TradeWindow { if ( TradeWindow.Price > 100){ if ( TradeWindow.Price * TradeWindow.Volume < 1000000) { output (TradeWindow);} }
These if statements tell the project server to output trade data values if the product of TradeWindow.Price * TradeWindow.Volume is less than 1 million. An else if statement executes if the conditions are not true.
Else if ( TradeWindow.Price > 10){ if ( TradeWindow.Price * TradeWindow.Volume < 10000) { output (TradeWindow);} }
The else if statement tells the project server to output trade data values greater than 10 if the total value of shares in the window are less then 10 thousand. An additional else statement executes if these conditions are not true.
Else { if ( TradeWindow.Price * TradeWindow.Volume < 1000) { output (TradeWindow);} } } ;END;
The else statement tells the project server to complete its output when the total value of shares in the window are less than 1000, and the preceding if/else conditions are not true.
The example then uses switch syntax to achieve the same overall conditions:
CREATE FLEX FlexCase IN TradeWindow OUT OUTPUT WINDOW FlexCaseOut Schema TradeSchema Primary Key (Ts) BEGIN ON TradeWindow { switch ( to_integer(log(to_float(TradeWindow.Price)))){ case 0: // price less than 10 if ( TradeWindow.Price * TradeWindow.Volume < 1000) { output (TradeWindow);} break; case 1: // price between 10 and 100 if ( TradeWindow.Price * TradeWindow.Volume < 10000) { output (TradeWindow);} break; default: // price 100 or bigger if ( TradeWindow.Price * TradeWindow.Volume < 1000000) { output (TradeWindow);} break; } } ; END ;
The switch syntax also converts TradeWindow.Price values to float, applies a logarithm to the values, then converts them to integer.