:SWITCH ... :CASE ... :OTHER ... :ENDSWITCH
Script Statement: It verifies whether the value of a variable complies with certain values and, depending on the result, it runs various statements.
Syntax
:SWITCH Variable
:CASE Value1
[Statements]
[:CASE Value2
[Statements]
...
]
[:OTHER
[Statements]
...
]
:ENDSWITCH
Syntax |
Description / Format |
---|---|
Variable |
The name of the variable whose value should be verified. |
Value1, Value2... |
Conditions or the values that form the conditions. |
Statements | One or several statements that should be processed when the variable complies with the specified value. Format: script statement |
Comments
A SWITCH statement forms one or several conditions by running various statements depending on a variable's value. A :SWITCH block consists of one or several :CASE statements and must end with :ENDSWITCH.
With each :CASE statement, you determine a value or an expression that should be evaluated. It is followed by the statements that should be processed when the value or the expression applies. These statements end with a new :CASE line or with :ENDSWITCH.
You can define an :OTHER branch additionally whose statements will be processed when no :CASE statement applies.
Note that the :OTHER statement must only be used after the last :CASE statement.
You can also use multiple :CASE statements in a sequence without separating them with statements. They are connected by OR relations. Note that this is only useful in complex expressions.
You can also use :IF statements to evaluate expressions. Their statement block, however, is limited to one condition and one Else condition.
As values, you can also use complex expressions such as arithmetic terms:
:SWITCH &NUM#
:CASE 3*(5-2)
: PRINT "&NUM# = 9"
:ENDSWITCH
You can also use the construct between value1 and value2, and the operators <, >, <>, <=, >=, = in :CASE lines. In this case, you must specify the string "Y" instead of the variable name:
:SET &STATUS# = GET_STATISTIC_DETAIL(&RUNID#,STATUS)
:SWITCH "Y"
:CASE &STATUS# between 1300 and 1599
:CASE &STATUS# between 1700 and 1799
: PRINT "The task &RUNID# is active."
:CASE &STATUS# between 1600 and 1699
: PRINT "The task &RUNID# is in a waiting condition."
:CASE &STATUS# between 1800 and 1899
: PRINT "The task &RUNID# has aborted."
:CASE &STATUS# >= 1900
: PRINT "The task &RUNID# has successfully ended."
:ENDSWITCH
You can use the predefined variable &$PLATFORM# with this script statement. But note that using this predefined variable in a Generic Job object requires the variable &AGENT# also be defined in that script. Otherwise an error occurs, since for the Generic object by definition no host is defined, when you create it.
Examples
The following example retrieves the current day of the week as a number and verifies it using a SWITCH statement. Mondays and Fridays, a specific job starts.
:SET &DATE# = SYS_DATE_PHYSICAL("DD.MM.YYYY")
:SET &WEEKDAY# = WEEKDAY_NR("DD.MM.YYYY:&DATE#")
:SWITCH &WEEKDAY#
:CASE 1
: SET &ACT# = ACTIVATE_UC_OBJECT(JOBS.MONDAY, WAIT)
:CASE 5
: SET &ACT# = ACTIVATE_UC_OBJECT(JOBS.FRIDAY, WAIT)
:OTHER
: PRINT "No Processing."
:ENDSWITCH
This script can be used in a Generic Job object:
:SWITCH &$PLATFORM#
:CASE "WINDOWS"
! insert these lines in your script to determine if an error occurred
! @set retcode=%errorlevel%
! @if NOT %ERRORLEVEL% == 0 goto :retcode
!
:CASE "UNIX"
:OTHER
:ENDSWITCH
See also:
Script Element | Description |
---|---|
They analyze an expression and depending on the result, they run statements. |
Script Elements - Data Sequences
About Scripts
Script Elements - Alphabetical Listing
Script Elements - Ordered by Function