Adding a Switch Statement (Release 9.2.9.4)

You can add a Switch statement to the logic extension and define several possible execution paths.

A switch statement is faster to create than an If Else statement in cases where there are many similar conditions involving the same left-hand operand.

The Switch Statement enables you to define evaluation criteria in the form of cases. Using this format, you can compare criteria with the same left operands, the equals operator, and multiple right operands. In this way you can efficiently create cases to evaluate data structure elements, variables, system literals, and constants to create branches of logic.

To add a Switch statement:

  1. On the design panel, hover over the location where you want to add a Switch statement and click the + icon. Select Switch from the Action menu. The system inserts a Switch statement along with the Case and Default branches on the design panel and displays the Switch panel on the right.

    Note: You can also drag and drop the Switch statement from the Logic Statements panel to the required location on the design panel.
  2. On the Switch panel, in the Switch section:

    • Enter the values in the Label and Description fields.

    • From the Left Operand drop-down list, select the required value.

      The Left Operand drop-down list may include these values: variable, data structure (single or array columns), system literal, system variable, data types such as Number, Integer, String, Char, Date, Utime, and Identifier. This list does not support Boolean or Array parent types. The system displays an array icon next to the array columns.

    Note: Any modification to the left operand will clear the right operand list from all the branches to ensure compatibility with the new data type.
  3. On the Switch panel, in the Case section, you must define the right operand values for all the Case branches. Enter a value in the Branch Label field.

    To define the right operand for the Case branch, click the Launch Criteria Builder icon. The system displays the Right Operands window containing the following two panels:

    • Criteria Panel (left panel): Displays a table with the Edit icon. Click the Edit icon.

    • Object Selector Panel (right panel): Using this panel, filter and select the values for the Right Operands field. Various types of operands are supported including literals, <null> values, <blank> values, data structures, variables, system literals, and system constants, provided they match the data type of the left operand. You can click the Close or Open icons to hide or view this panel.

  4. Click Close.

    The mappings are displayed in the Case section of the Switch panel.

  5. In the Default section of the Switch panel, enter the value in the Branch Label field. This branch handles the unmatched values.

    Note: You can hover between the branches of a Switch statement on the design panel and click the + icon to add the new Case branches. You can define the right operands for the Case branches by clicking the Launch Criteria Builder icons in the Case sections of the Switch panel. You can click the Delete icon next to the Case section on the Switch panel to delete a Case branch. You must have at least one Case and one Default branch for a Switch statement to function.
  6. Click Save.

Branch Management

You can cut and copy the conditional branches (from If Else, While, and Switch statements) from one position and paste them to another position in the logic extension. To do so, right-click the conditional branch and select the Cut Branch, Copy Branch, and Paste Branch options.

These are the considerations:

  • When transferring a branch from a non-switch statement (If Else or While) to a non-switch statement using the copy/cut branch and insert branch/replace branch actions, the system maintains its existing values, and it is also backward compatible.

  • When transferring a branch from a Switch statement to a non-switch statement using the copy/cut branch and insert branch/replace branch actions, an empty right operands list is displayed for the non-switch branch.

  • When transferring a branch from a non-switch statement to a Switch statement using the copy/cut branch and insert branch/replace branch actions, an empty right operands list is displayed for the switch branch.

  • When transferring a branch from one Switch statement to another Switch statement using the copy/cut branch and insert branch/replace branch actions, if both the source and target switch branches have the same left operand, the right operand values are transferred. Otherwise, an empty right operands list is displayed.

  • The statement block within a branch is transferred from the source to the target branch, irrespective of the target statement type and left operand.