IF

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:

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:

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


This picture shows the syntax of the IF statement.
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:

  1. From the Welcome window, click on Applications —> 3270 Servers
  2. Selecting the IF statement : Click Statements —> Conditional.

    The system displays the Conditional Definition window.

  3. Click the button next to IF condition THEN.
  4. If the statement is to test when the condition is not true, click the NOT pushbutton.
  5. Defining the condition : To define the condition, either type it in the condition field or click condition.

    The system displays the Condition Definition window.

  6. In the Condition Definition window, click the pushbutton next to Condition Type, then click:
    • Compare to compare two values
    • Field Exists to verify that a field exists on the current 3270 screen
    • Check Screen to verify that the current 3270 screen is the one you expect
    • Check Field Attribute to verify that a field has the expected attribute.

      The Condition Definition window changes appropriate to the condition type you select.

  7. 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.
  8. To define a Field Exists, Check Screen or Check Field Attribute condition, refer to the descriptions for these statements.
  9. Click OK.

    The Conditional Definition window displays the defined condition in the condition field.

  10. If required, click AND and click AND or OR. Repeat this procedure, starting from Step 4.
  11. Adding the IF statement to the script : Click OK.

    The IF statement is added to the script.

  12. 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.

  13. Repeat Step 12 for each action to be performed when the IF condition is true.
  14. 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.
  15. 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.

  16. Adding ELSE or ELSEIF to the script : Click OK.

    The ELSE or ELSEIF keyword is added to the script.

  17. 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.