Switch stage example
Use the Switch stage to implement a switch statement.
The following example shows how a Switch stage implements a switch statement:
switch (selector)
{
case 0: // if selector = 0,
// write record to output data set 0
break;
case 10: // if selector = 10,
// write record to output data set 1
break;
case 12: // if selector = discard value (12)
// skip record
break;
case default: // if selector is invalid,
// send row down reject link
};
The metadata input to the switch stage listed in the following
table.
Column name | SQL type |
---|---|
Select | Integer |
col1 | Char |
col2 | Char |
col3 | Char |
In this example, the Select column is the selector. Each input row is assigned to an output data set based on the value of the selector.
To implement the switch statement, the properties of the stage are set to the following
values.
Property | Value |
---|---|
Selector | Select |
Selector Mode | User-defined Mapping |
Case | 0=0 |
Case | 10=1 |
Case | 12=5 |
Discard Value | 5 |
In this example, any rows that have a 0 in the Select column are sent to output link 0. Any rows that have a 10 in the Select column are sent to output link 1, and any rows that have a 12 in the Select column are discarded.