ABL Essentials
Using Basic ABL Constructs : Putting a calculation into your procedure : Arithmetic expressions and operands

# Arithmetic expressions and operands

ABL supports the set of arithmetic operands described in the following table. You can use these operands to define expressions. You might be familiar with them from other programming languages you have used.
 Symbol Explanation + Adds numeric values; concatenates character strings - Subtracts numeric values or date values * Multiplies numeric values / Divides numeric values
The AVM evaluates operators of equal precedence from left to right. Otherwise, the AVM evaluates the operator of higher precedence, as shown in the following table. Use parentheses to raise the precedence of a given expression.
 Precedence (highest to lowest) Operator function Symbol 11 Numeric negative (unary)Numeric positive (unary) -+ 10 Numeric moduloNumeric divisionNumeric multiplication MODULO/* 9 Date subtractionDatetime subtractionNumeric subtractionDate additionDatetime additionNumeric additionString concatenation ---++++ 8 Relational string matchRelational less thanRelational less than or equal toRelational greater thanRelational greater than or equal toRelational equal toRelational not equal toRelational string beginning MATCHESLT or GE or >=EQ or =NE or <>BEGINS 7 Bitwise NOT (unary) NOT 6 Logical NOT (unary) NOT 5 Bitwise AND AND 4 Bitwise XOR XOR 3 Bitwise OR OR 2 Logical AND AND 1 Logical inclusive OR OR
(The bitwise operators are used with flag enumeration types. For more information, see OpenEdge Development: ABL Reference.)
There is one special thing you need to know when you are writing expressions involving these operands. Because ABL allows the use of a hyphen as a character in a procedure name, variable name, or database field name, the AVM cannot recognize the difference between a hyphen and a minus sign used for subtraction, which are the same keyboard character. For example, there is no way for the syntax analyzer to tell whether the string ABC-DEF represents a single hyphenated variable or field name, or whether it represent the arithmetic expression ABC minus DEF, involving two fields or variables named ABD and DEF. For this reason, you have to put a space or other white space characters around the "-" character when you use it as a minus sign for subtraction of one number from another. Note that you don't have to insert a space after a minus sign that precedes a negative number, such as –25. For consistency, the other arithmetic operands also require white space. If you forget to put it in, you'll get an error, except in the case of the forward slash character. In the case of the slash, if you leave out the white space, the AVM interprets the value as a date! So, for example, 5/6 represents May 6th, not a numeric fraction.
To illustrate how to use arithmetic operands in the sample procedure, you need to determine whether the CreditLimit of the Customer is less than twice the outstanding Balance. If this is TRUE, then you must display the ratio of CreditLimit to Balance. Otherwise you display the Orders for the Customer. Add the following code, just in front of the FOR EACH Order OF Customer statement that's already there:
 IF Customer.CreditLimit < 2 * Customer.Balance THEN  DISPLAY "Credit Ratio:" Customer.CreditLimit / Customer.Balance.ELSE   FOR EACH Order OF Customer:
You can add parentheses to such an expression to make the grouping of terms explicit. Otherwise, the AVM observes the standard rules of precedence. Multiplication and division are performed before addition and subtraction, and all such calculations are performed before a comparison operation.
The expression following the IF keyword compares the CreditLimit field from the current Customer record with two times the value of the Balance field. If the first value is less than the second, then the expression is TRUE and the statement following the THEN keyword is executed, which displays the string expression Credit Ratio: followed by the value of the CreditLimit divided by the Balance.
The ELSE keyword is followed by the entire FOR EACH Order block, so that block of code, which displays all the Orders of the Customer, is skipped if the expression is TRUE, and executed only if it is FALSE.
To see the result of this change, run your procedure again. For a Customer where the ratio is greater than or equal to 2, the Orders display as before. For a Customer where the ratio is less than 2, the new expression is displayed instead: