ScriptEigener Objekttyp in der Automation Engine Statements: They analyze an expression and depending on the result, they run statements.
Syntax
:IF Condition
[Statements]
[:ELSE]
[Other Statements]
:ENDIF
Syntax |
Description/Format |
---|---|
Condition |
A mathematical expression that consists of script literals, script variables, script functions or numbers with the possible results "True" or "False" |
Statements |
One or more statements that will be executed when the condition
is "True" |
Other Statements |
One or more statements that will be executed when the condition
is "False" |
Comments
An IF statement is a control structure that you can use to process scripts depending on the result that a condition supplies. A condition is a logical expression.
When the condition applies (it is true), the statements are executed.
When the condition does not apply (it is false), the :ELSE statements are processed. When the IF block does not contain an :ELSE branch, it continues with the next line that follows the :ENDIF statement.
IF blocks can also be nested. The nesting depth is not limited.
IF blocks do not necessarily include ELSE branches.
When strings exceed 1024 characters, a difference in characters beyond the 1024th character will not be recognized by an :IF statement in the script. The comparing algorithm only checks the first 1024 characters of a string.
Using an OR keyword
To link a condition to several values or to link several individual conditions , you use OR as the keyword.
Conditions show the following structure:
ValueComparison operatorComparison Value[OR Comparison Value...] |
---|
For example:
:IF &DEP# = "EDP" OR "AE"
You can use up to 13 ORs in a condition.
Comparison operators
A condition contains one of the following comparison operators:
Operator |
Short form |
Rule |
---|---|---|
= |
EQ |
This expression is "True" if at least one of the comparison values equals the Value. |
<> |
NE |
This expression is "True" when none of the comparison values equals the Value. |
< |
LT |
This expression is "True" if one comparison value corresponds to the defined condition. |
> |
GT |
|
<= |
LE |
|
>= |
GE |
A numerical comparison takes place when both comparison values of a condition have a numerical value (data types signed, unsigned or float). A string comparison takes place in all other cases. Note that leading zeros are only ignored in numerical comparisons.
The following condition supplies "True":
:IF "0" = "0"
An alpha-numeric comparison takes place when there are no numerical values.
The following condition supplies "False":
:IF "0" = "abc"
Script lengths are not checked during the comparison process. The following condition supplies "True" because "S" comes before the "U" in the alphabet.
:IF "Smith" < "AE"
Note that you must define the script variables that you use in a condition beforehand.
Conditions that include the keyword OR several times can show various behaviors depending on the operator.
For example:
In the following example, one of the values must apply in order to meet the condition.
:IF &WD# = "MON" OR "TUW" OR "WED"
The following condition is only met if the variable does not comply to any of the three values.
:IF &WD# <> "THU" OR "FRI" OR "SAT"
Trailing Blank Spaces Are Not Considered
Trailing blank spaces are not considered in string comparisons. Therefore, blank strings always are equal independent on their length.
For example:
:set &a= 'a '
:set &b= 'a'
:if &a = &b
:print 'true'
:endif
In this case, comparison of &a with &b would return true as trailing blanks are eliminated before the comparison.
Examples
The following examples show different ways of defining a condition. The examples 1 to 3 put a script variable into relation with one or more comparison values. The fourth example uses the return code of a function.
:IF &USER# = "TSOS"
!...
:ENDIF
:IF &DAT1# = &DAT2# OR " "
!...
:ENDIF
:IF GET_ATT(OO)
= "J"
!...
:ENDIF
See also:
Script element | Description |
---|---|
:SWITCH... :CASE... :ENDSWITCH | It verifies whether the value of a variable complies with certain values and depending on the result, it runs various statements. |
This is used to define a loop for the repeated execution of script elements. |
Script Elements -
Script Structure and Processing
About Scripts
Script Elements - Alphabetical Listing
Script Elements - Ordered by function