IF...ENDIF
Top  Previous  Next

Use an IF...ENDIF structure in a command file to cause a block of commands to be run when the specified conditions are met.

ifendif

Options

condlist

Lists a set of conditions that combine to form a statement that is either true or false. Conditions are combined with the connecting operators AND, OR, AND NOT, and OR NOT.

else-block

Contains one or more R:BASE commands to execute when the conditions specified in condlist are false.

then-block

Contains one or more R:BASE commands to execute when the conditions specified in condlist are true.

About the IF...ENDIF Command

When the conditions in an IF...ENDIF structure are true, R:BASE runs all the commands between THEN and ELSE, or if the ELSE option is not included, between the THEN and ENDIF.

If you use the ELSE option and the conditions are false, R:BASE runs the block of commands between the ELSE and the ENDIF. If you do not use the ELSE option and the conditions are false, R:BASE runs the command line immediately after ENDIF.

IF...ENDIF structures can be nested with other IF...ENDIF structures.

IF...ENDIF structures can be on a single line in a command file. You cannot put an IF...ENDIF structure on a single line when any of the following occur in a command file:

·The last command in the then-block is QUIT.  
·The structure contains an else-block.  
·The structure contains a RUN command.  

Using Conditions in an IF...ENDIF Structure

The conditions for an IF...ENDIF structure are listed in the table below.

Condition            Description   
varname IS NULL             The value of the variable is null.

varname IS NOT NULL          The value of the variable is not null.

varname CONTAINS 'string'         The variable has a TEXT data type and contains a 'string' as a substring
               in the variable value.

varname NOT CONTAINS 'string'      The variable has a TEXT data type and a 'string' is not contained as a                substring in the variable value.

varname LIKE 'string'         The variable equals a 'string.' A 'string' can contain wildcards.

varname NOT LIKE 'string'         The variable does not equal the 'string'. A 'string' can contain
               wildcards.

varname BETWEEN value1 AND value2   The value of the variable is greater than or equal to value1 and less
               than or equal to value2. The variable and the values must be the
               same data type.

varname NOT BETWEEN value1 AND value2   The value of the variable is less than value1 or greater than value2.                The variable and the values must be the same data type.

item1 op item2            Item1 has the specified relationship to item2. Item1 can be a column
               name, value, or expression; item2 can be a column name, value, or                expression.

The valid operators (op) for the conditions in an IF...ENDIF structure are listed in the table below. Do not use wildcard characters with these operators.

Operator   Description   
= or EQ      Equals
<= or LE      Less than or equal to
>= or GE      Greater than or equal to
< or LT      Less than
> or GT      Greater than
<> or NE      Not equal

An expression can be substituted for the first variable in each of the conditions. The second variable in the comparison must be dotted so that the value of the variable is used, not the variable name.

Wildcards can be used with LIKE or NOT LIKE (for example, varname LIKE 'string%').

If you use multiple AND and OR operators, you must enter them in the correct order, or use parentheses to obtain the desired result. If SET AND is on (the default setting) conditions connected by AND are evaluated first; then conditions connected by OR are evaluated.

Examples

The following command lines show three nested IF...ENDIF structures.

IF vqtyord > .vlastqty THEN
 IF vqtyord <> 0 THEN
 IF vchng > 0 AND vbackord IS NOT NULL THEN
 .
 .
 .
 ELSE
 .
 .
 .
 ENDIF
 ENDIF
 ENDIF

The following example shows an IF...ENDIF structure on a single line.

IF v2 = 0 THEN ; SET VARIABLE v1 = (.v1 + 1) ; ENDIF