Use the IF statement to evaluate whether a condition is
TRUE or FALSE, and perform specified actions based on the result.
A condition can be a comparison between two values or
any of the following script language statements:
- CHECK_ATTRIBUTE
- CHECK_SCREEN
- EXISTS
Conditions can be grouped to form complex conditions using
the operators AND, OR, and (unary) NOT.
The IF statement is always paired with a THEN keyword
to specify the actions to be performed when the condition is true.
Optionally, an ELSE or ELSEIF keyword can follow a statement after
the THEN keyword to specify the action to be performed when the condition
is false.
If both sides of the condition are numeric then a numeric
comparison is done.
Data is treated as numeric under the following conditions:
- The only characters it contains are 0 to 9, not more than one
period (.), and not more than one hyphen (-). For example:
-978.32
- Data starting with a hyphen (-), representing a minus sign, is
treated as having a negative value. For example:
-123
Therefore, the following strings are treated as numeric
(with a value of zero):
-
|
0
|
.
|
-.
|
0.
|
.-
|
-.0
|
0.0
|
.0
|
-0.
|
|
|
-0.0
|
|
|
Data is treated as a string if it has:
If you need to ensure a that string comparison is performed,
then at least one side of the condition must be non-numeric. You may
need to force this by concatenating a non-numeric character to the
data.
Syntax
Note: Arithmetic operations are not supported inside conditions.
For example,
IF variable < (10 * 5) THEN .
is
not valid. The following is valid and produces the intended result:
temp_variable = 10 * 5
IF variable < temp_variable THEN ...
Examples
IF A > 10 THEN
.
.
.
ELSEIF A < 3 THEN
.
.
.
ELSEIF ( B = A AND C <= 20 ) OR ( X != A )
.
.
.
ENDIF
temp_num = 10 * 5
IF A < temp_num THEN
.
.
.
ENDIF
Procedure
To use the
3270 Script window’s Statements menu to define an IF statement, follow
this procedure:
- From the Welcome window, click on Applications
—> 3270 Servers
- Selecting the IF statement : Click Statements
—> Conditional.
The system displays the Conditional
Definition window.
- Click the button next to IF condition THEN.
- If the statement is to test when the condition is not true,
click the NOT pushbutton.
- Defining the condition : To define the condition,
either type it in the condition field or
click condition.
The system displays
the Condition Definition window.
- In the Condition Definition window, click the pushbutton next
to Condition Type, then click:
- To define a Compare condition:
- Type the name of the left operand variable in the Left
Operand field, or click Left Operand to
display the Term Definition window to select the operand.
- Click the pushbutton next to Operator,
then click the appropriate comparison operator.
- Type the name of the right operand variable in the Right
Operand field, or click Right Operand to
display the Term Definition window to select the operand.
- To define a Field Exists, Check Screen or Check
Field Attribute condition, refer to the descriptions
for these statements.
- Click OK.
The Conditional Definition
window displays the defined condition in the condition field.
- If required, click AND and
click AND or OR.
Repeat this procedure, starting from Step 4.
- Adding the IF statement to the script : Click OK.
The IF statement is added to the script.
- Defining THEN statements : Use the Statements menu
to define the statement that you want to execute when the IF condition
is true. Refer to the statement description for instructions.
The
statement is added to the script following the THEN keyword.
- Repeat Step 12 for each action
to be performed when the IF condition is true.
- Defining ELSE or ELSEIF keywords : If the statement requires
actions to be performed only when the IF condition is false, click Statements
—> Conditional.
In the Conditional Definition
window, click the button next to either:
- ELSE to define actions to be performed
when the IF condition is false, or
- ELSEIF condition THEN to define another
IF statement structure to be performed when the initial IF condition
is false.
- Defining an ELSEIF structure : To define an ELSEIF structure,
repeat this procedure starting from Step 5.
The statements are added to the script following the ELSEIF keyword.
- Adding ELSE or ELSEIF to the script : Click OK.
The ELSE or ELSEIF keyword is added to the script.
- Defining ELSE statements : Use the Statements menu
to define the ELSE statements that you want to execute when the IF
condition and all ELSEIF conditions are false. Refer to the statement
descriptions for instructions.
The statements are added to the
script following the ELSE keyword.