[IF] (conditionally execute a group of statements)
[IF] conditionally executes a group of statements based on specified conditions.
If the first condition is true, the processing beginning with [THEN] is executed. If the first condition is false, the[ELSEIF] tag can be used to conditionally execute another group of statements. If neither of the conditions is true, processing beginning with [ELSE] is executed; if [ELSE] is not defined, no processing is executed.
Although you can specify any number of [ELSEIF] tags, it is better to use the [SWITCH] tag to specify constants when you need to compare a condition value to a large number of constants, because you do not need to nest the condition branches so deeply, thus producing code that is easier to read. For a coding example of the [SWITCH] tag, see [SWITCH] (conditionally execute a group of statements).
Syntax
[IF] condition-1 [THEN] processing-if-condition-1-is-true ([ELSEIF]) condition-2 ([THEN]) processing-if-condition-1-is-false-and-condition-2-is-true ([ELSE]) processing-if-all-conditions-are-false [IF_END]
Values
-
condition-1, condition-2
Specifies the conditions used to determine whether to branch.
-
processing-if-condition-1-is-true
Specifies the processing to be executed when condition-1 is true.
-
processing-if-condition-1-is-false-and-condition-2-is-true
Specifies the processing to be executed when condition-1 is false and condition-2 is true. This coding is optional. If you omit this coding, do not specify a condition for it.
-
processing-if-all-conditions-are-false
Specifies the processing to be executed when all the conditions are false. This specification is optional.
Example
- Example 1
-
The following example searches for the asset information for asset number 10000. If data is found ([THEN]), that data is deleted; if no data is found ([ELSE]), the termination status is displayed.
[CLASS_FIND] AssetInfo [FIND_DATA] (AssetInfo.AssetNo = '10000') [GET_VALUE] AssetID = AssetInfo.AssetID [SET_VALUE] STATUS = $GETSTATUS() [IF] STATUS = NORMAL [THEN] [DELETE] AssetInfo [DATA] AssetInfo.AssetID = AssetID [SET_VALUE] MSG = 'CLASS_FIND (' + STATUS + ')' $ECHO(MSG) [ELSE] [SET_VALUE] MSG = 'CLASS_FIND (' + STATUS + ')' $ECHO(MSG) [IF_END]
- Example 2
-
The example below performs the following processing:
-
If the data is updated normally ([THEN]), the termination status is displayed.
-
If the data has already been updated by another control process ([ELSEIF], [THEN]), a message is output.
-
If no data exists ([ELSE]), 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() [IF] STATUS = NORMAL [THEN] [SET_VALUE] MSG = 'UPDATE (' +STATUS+ ')' $ECHO(MSG) [ELSEIF] STATUS = MULTI [THEN] [SET_VALUE] MSG = 'Asset number [10000] is updated already.' $ECHO(MSG) [ELSE] [APPEND] AssetInfo [DATA] AssetInfo.AssetID = '10000' AssetInfo.AssetNo = '10000' AssetInfo.AssetKind = '001' AssetInfo.AssetBranchNo = 0 [SET_VALUE] MSG = 'UPDATE (' +STATUS+ ')' $ECHO(MSG) [IF_END]
-