[SWITCH] (conditionally execute a group of statements)
[SWITCH] executes processing when a condition value matches a specified constant.
The [SWITCH] tag is more convenient to use than the [IF] tag when you wish to compare a condition to a large number of constants, because the statements are nested less deeply. When the condition value matches a constant, the processing following the associated [CASE] tag is executed. When the condition value does not match any of the specified constants, the processing following [DEFAULT] is executed; if [DEFAULT] is not defined, no processing is executed.
If the same constant is specified under more than one [CASE] tag, processing is executed beginning with the [CASE] tag in which the constant was first specified (beginning from the left if all of the relevant coding is specified on one line), and continues until all processing specified for the condition value matching those constants has executed.
Syntax
[SWITCH] condition-value [CASE] constant processing-if-condition-value-matches-the-constant ([CASE]) constant[,constant[,constant...]] processing-if-condition-value-matches-any-of-the-constants ([DEFAULT]) processing-if-no-constant-is-matched [SWITCH_END]
Values
-
condition-value
Specifies a condition value.
-
constant
Specifies a constant; when this constant matches the condition value, the associated processing is executed. Multiple constants can be specified by separating them with commas.
-
processing-if-condition-value-matches-the-constant
Specifies the processing to be executed when the condition value matches the associated constant. If you want to execute only the processing specified for the first constant that the condition value matches, specify $BREAK() at the end of the [CASE] tag block.
-
processing-if-condition-value-matches-any-of-the-constants
Specifies the processing to be executed when the condition value matches any one of the constants. If you want to execute only the processing specified for the first constant that the condition value matches, specify $BREAK() at the end of the [CASE] tag block. This specification is optional.
-
processing-if-no-constant-is-matched
Specifies the processing to be executed when the condition value does not match any of the constants. You can specify the [DEFAULT] tag before the [CASE] tags if you wish. This specification is optional.
Example
The example below executes the following processing:
-
If the data is updated normally (STATUS = 'NORMAL'), the termination status is displayed.
-
If the data has already been updated by another control process (STATUS = 'MULTI'), a message is output.
-
If no data exists ([DEFAULT]), data is added.
[UPDATE] AssetInfo [DATA] AssetInfo.AssetID = '10000' AssetInfo.AssetNo = '10000' AssetInfo.AssetKind = '001' AssetInfo.AssetBranchNo = '0' AssetInfo.UpdateTime = _UpdateTime [SET_VALUE] STATUS = $GETSTATUS() [SWITCH] STATUS [CASE] 'NORMAL' [SET_VALUE] MSG = 'UPDATE (' +STATUS+ ')' $ECHO(MSG) $BREAK() [CASE] 'MULTI' [SET_VALUE] MSG = 'Asset number [10000] is updated already.' $ECHO(MSG) $BREAK() [DEFAULT] [APPEND] AssetInfo [DATA] AssetInfo.AssetID = '10000' AssetInfo.AssetNo = '10000' AssetInfo.AssetKind = '001' AssetInfo.AssetBranchNo = '0' [SET_VALUE] MSG = 'UPDATE (' +STATUS+ ')' $ECHO(MSG) $BREAK() [SWITCH_END]