# REXX operators

There are several types of operators allowed in QMF expressions: arithmetic, comparison, concatenation, and logical (or Boolean). Each operator (except the prefix operator) acts on two terms. These terms can be symbols, functions, or subexpressions in parentheses. Each prefix operator acts on the term or subexpression that follows it.

## Arithmetic operators

- +
- Add
- -
- Subtract
- *
- Multiply
- /
- Divide
- %
- Divide and return only the integer part of the quotient
- //
- Divide and return only the remainder (not modulo because the result can be negative)
- **
- Raise the number to a whole-number power (exponentiation)
- Prefix -
- Negate the next term
- Prefix +
- Take the next term as-is

## Comparative operators

- ==
- Exactly equal (identical)
- =
- Equal (numerically or when padded)
- ¬==, /==
- Not exactly equal (inverse of ==)
- ¬=, /=
- Not equal (inverse of =)
- >
- Greater than
- <
- Less than
- < >
- Not equal
- >=
- Greater than or equal
- ¬<
- Not less than
- <=
- Less than or equal
- ¬>
- Not greater than

## Concatenation operator

- ||
- Concatenate terms (you can use no blanks or one blank)

REXX provides other concatenation operators.

## Logical (Boolean) operators

- &
- AND (returns 1 if both terms are true)
- |
- Inclusive OR (returns 1 if either term is true)
- &&
- Exclusive OR (returns 1 if either term is true, but not both)
- Prefix ¬
- Logical NOT (negates; 1 becomes 0 and vice-versa)

## Operator priorities

Expression evaluation is from left to right. You can modify this order by using parentheses and operator priority.

Use parentheses to clarify the meaning when the priority of operators is not obvious. An expression in parentheses is evaluated first.

`operator2`

has a higher priority than `operator1`

,
the expression (`term2 operator2 term3 ...`

) is evaluated
first, applying the same rule repeatedly, as necessary: `term1 operator1 term2 operator2 term3 ...`

For
example, * (multiply) has a higher priority than + (add), so 3+2*5
evaluates to 13, rather than 25, which results if strict left-to-right
evaluation occurred.- + - ¬
- Prefix operators
- **
- Exponentiation
- * / % //
- Multiply and divide
- + -
- Add and subtract
- ||
- Concatenation (with or without blank)
- =, >, ...
- All comparison operators
- &
- And
- |, &&
- Or, exclusive or

The & and && operators must be followed by a blank in calculation expressions to differentiate them from substitution variables.

For operators of equal priority (the multiply and divide operators, for example), the left-to-right rule prevails.

The only difference between these priorities and conventional algebra is that the prefix minus operator has a higher priority than the exponential operator. Thus -3**2 evaluates to 9, not -9.

## Testing for specific values within a REXX expression

The REXX @IF function is used to test for specific values within a REXX expression and then interpret the associated REXX expressions and return the results.

You can use the @IF function anywhere you normally use a REXX expression. REXX expressions can be used in FORM.CALC, FORM.CONDITIONS and FORM.COLUMNS (Column Definition).

^{1}A valid REXX expression that can be reduced to a 0 or 1. Typically contains a REXX comparative operator. The @IF function tests the comparison and if the result is 1, the expression following the function is evaluated and the results are returned. The @IF function evaluates the comparisons left to right until a true comparison is found. If no comparisons are found to be true, then the last expression is interpreted and the results are returned.^{2}A valid REXX expression consisting of terms (strings, symbols, and functions) interspersed with operators and parentheses. If the comparison preceding the expression is true, the expression is interpreted and the results are returned.^{3}A valid REXX expression. If no comparisons are true, then`expression_N`is interpreted and the results are returned.

- There must be an odd number of arguments.
- The minimum number of arguments is 3; the maximum is 19.
- The first token must be @IF and it must be immediately followed by a left parenthesis.
- Arguments must be delimited by commas.
- The argument list must end with a right parenthesis.
- The last argument serves as an "otherwise", or default, expression.
- If an odd-numbered argument is not the last, then it is a comparison.
- If PASS NULLS is set to YES and the expression contains a substitution variable that is null, undefined, overflows, has no instance, or no relationship, then the entire expression will be set to the value that represents that condition. This reduction is performed only on expressions, not comparisons.
- If PASS NULLS is set to YES and the expression contains more than
one substitution variable that is null, undefined, overflows, has
no instance, or no relationship, then the following order of precedence
will be used for expression reduction:
- Undefined
- Overflow
- Null
- No instance
- No relationship

The use of multiple arguments (comparisons and expressions) passed to the @IF function will eliminate the need to nest @IF functions (nested @IF functions are not supported for expression reduction).

`@If(&3=10,’MGMT’,&5=DSQNULL,’N/A’,&5/&4*100)`

This expression can be logically restated as: ```
Select
When &3 = 10 Return MGMT /* All Department 10 employees are managers */
When &5 is NULL Return N/A /* Comission is NULL, mark N/A */
Otherwise Return &5/&4*100 /* For all others, calculate commission % */
```

```
ID NAME DEPT SALARY COMM COL1
--- -------- ---- -------- ------ ----
10 SANDERS 20 18357.50 - N/A
20 PERNAL 20 18171.25 612.45 3.37
30 MARENGHI 38 17506.75 - N/A
110 NGAN 15 12508.20 206.60 1.65
120 NAUGHTON 38 12954.75 180.00 1.38
160 MOLINARE 10 22959.20 - MGMT
```