ABL Essentials

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 modulo Numeric division Numeric multiplication | MODULO / * |

9 | Date subtraction Datetime subtraction Numeric subtraction Date addition Datetime addition Numeric addition String concatenation | - - - + + + + |

8 | Relational string match Relational less than Relational less than or equal to Relational greater than Relational greater than or equal to Relational equal to Relational not equal to Relational string beginning | MATCHES LT or < LE or <= GT 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:

You might notice a couple of things about this display:

Because the CreditLimit check is in the block of code where the procedure retrieves and displays Customers, it is displayed in the same frame as the Customer information. You can give names to frames to be more specific about the frame in which to display objects, as well as where in the frame each element is displayed.

The AVM understands enough about what is going on here to clear and hide the Order frame if it's not being displayed for the current Customer (because the CreditLimit to Balance ratio is being displayed instead). This is part of the very powerful default behavior of the language.

© 2017 Progress Software Corporation and/or one of its subsidiaries or affiliates. All rights reserved.

Progress® OpenEdge® Release 11.7