Previous Topic: &HEXPACK

Next Topic: &INTCLEAR


&IF

The &IF verb conditionally executes a command, statement, or DO group.

This verb has the following format:

&IF logical expression
[ { AND | OR } logical expression ] ...
    &THEN command or statement

&IF defines a logical expression and tests the truth of that expression, or defines multiple logical expressions connected by AND or OR operators and tests the truth of those expressions. If the result is true, the command or statement following the &THEN is executed.

If the result is false the next statement in the procedure sequence is executed. See the &ELSE statement description for an account of the support for the conditional execution of a command or statement associated with the false condition arising from &IF.

&IF supplies logical operators that are used to test the values of individual bit settings in hexadecimal variables.

See the &DO, &DOWHILE, and &DOUNTIL statement descriptions for an explanation of how to group commands and statements for execution in association with both the true condition, and the &ELSE false condition.

Operands:

logical expression

An expression in the form:

value1 relational-operator value2

value1 and value2 are either variables or constants, and relational-operator is one of the following logical operators:

Blanks must separate the logical operator from the values being tested.

Before the comparison, both values are translated to uppercase (by default) and all leading and trailing blanks are stripped. If either value is a series of blanks, it is treated as a single blank value. These changes apply only to the comparison operation and do not change either value for subsequent processing. (You can use the &CONTROL IFCASE option to suppress uppercase translation before the comparison.)

If operating in a system in which SYSPARMS DBCS=YES is active, no translation into uppercase is made.

When the logical operator indicates a bit test function, value1 and value2 are in hexadecimal format. Both values are regarded as the character representation of a hexadecimal byte; for example, 01 is treated as representing the hexadecimal byte X'01'. When performing bit tests, value1 must be at least two bytes long. The first two characters are combined to represent the target hexadecimal byte, which is tested against the two-byte value of value2.

value2 must be two bytes only, in the range 00 to FF. The bits set in value2 are tested against the byte represented by value1, according to the logical operator specified.

The operator BO signifies that all bits tested must be set for the expression to be true. BZ signifies that all bits tested must be set off for the expression to be true. BM specifies that if the tested bits are a mixture of on and off, the expression is true.

AND

Connects a series of logical expressions into a logical expression group. Each individual expression in the group must be true for the group as a whole to be considered true. AND takes precedence over OR.

OR

Connects a series of logical expression groups. The overall true/false analysis of the statement is determined by the true/false status of the individual groups, reading from left to right of the &IF statement. If any one group is found to be true, then the statement result is true. If all groups are found to be false then the statement result is false.

&THEN

Separates the right most logical expression or logical expression group from the command or statement that is to be executed if the statement is true. &THEN must have at least one blank on either side. &THEN is mandatory.

command or statement

Specifies the command or statement for execution if the statement is found to be true. The command or statement must be coded on the same statement as &IF.

Examples: & IF

&IF &DAY EQ WED &THEN +
   -START PROC2 
&IF .&1 = .  &THEN +
   &WRITE DATA=ERROR, OPERAND OMITTED
&IF &HEXFLAG BO 02 &THEN +
   &GOTO .BITON 
&IF &HEXFLAG BZ 03 &THEN +
   &GOTO .BITSOFF 
&IF .&1 EQ .LU AND .&2 NE . &THEN +
   &GOTO .ACTLU 
&ELSE +
   &GOTO .ERRORMSG

Notes:

Variable substitution is performed before processing the &IF statement. If a variable has a null or undefined value when substitution is performed, it is eliminated from the statement. For this reason, take care when testing variables if it is possible for no value to be assigned. For example, if an operator is required to enter a variable when a procedure is invoked, the procedure must then test that a variable has been entered or omitted. For the following statement:

&IF &1 EQ YES &THEN ....and so on

&1 is expected to be set to a value entered by the operator. A syntax error results if a value is not entered. After syntax substitution and before executing the &IF, the statement would appear as:

&IF EQ YES &THEN ....and so on

The variable &1 has been eliminated as it has a null value. This is easily overcome by prefixing the same constant to either side of the expression:

&IF .&1 EQ .YES &THEN ....and so on

In this case, if &1 is not set to a value, the resulting expression before executing the &IF would appear as:

&IF . EQ .YES &THEN ....and so on

No syntax error occurs, as the statement is still syntactically correct. If the &IF test is false, the &ELSE statement is used to indicate an alternative processing course. A subsequent &ELSE statement is optional. If the &IF test is true, the &ELSE action is ignored and processing resumes at the statement after completing the &ELSE process.

Note: &ELSE cannot be coded on the same statement as the associated &IF. &THEN must be coded on the same statement as the associated &IF.

More information:

&ELSE

&DO

&DOWHILE

&DOUNTIL

&GOTO