Easytrieve Order of Evaluation

When one line contains many operators, Easytrieve does not read strictly left to right. Order of evaluation—operator precedence—decides which operations bind first. Multiply before add. Arithmetic before greater-than. AND before OR. Exponentiation before multiply. Beginners who write IF A + B * C GT D intending (A + B) * C get silent wrong branches because B * C computed first. Payroll analysts who write IF STATUS EQ A OR STATUS EQ B AND GROSS GT 0 may intend OR across statuses with AND gross guard but precedence groups AND first. This page presents the precedence hierarchy Broadcom documentation implies, shows worked examples, contrasts default rules with parentheses override, and gives shop-safe habits: parenthesize mixed logical lines, split dense formulas to work fields, and trace boundary test cases when auditing legacy programs.

Progress0 of 0 lessons

Precedence Hierarchy Overview

From highest to lowest binding (typical rules)
RankOperatorsNotes
1 (tightest)Parentheses ( )Innermost group first
2** exponentiationPower before multiply
3* /Multiply divide left to right
4+ -Add subtract left to right
5EQ NE GT LT GE LE THRURelational compare
6NOTNegate condition
7ANDLogical and
8 (loosest)ORLogical or

Exact NOT placement may vary by condition form—when uncertain, parenthesize NOT with the condition it negates. Class conditions like NUMERIC behave as atomic units at relational level when combined with AND OR.

Arithmetic Precedence Examples

RESULT = 10 + 5 * 2 yields 20 not 30—multiply 5 * 2 = 10, then add 10 + 10. RESULT = (10 + 5) * 2 yields 30—parens force add first. RESULT = 100 / 10 / 2 may divide left to right: 10 then 5 depending on associativity—verify with test DISPLAY on your release. RESULT = 2 ** 3 ** 2 may right-associate exponentiation in some languages—test 512 versus 64; parenthesize (2 ** 3) ** 2 when policy demands explicitness.

text
1
2
3
WS-A = 10 + 5 * 2 * Result 20 WS-B = (10 + 5) * 2 * Result 30 WS-C = GROSS - DEDUCT * RATE * Multiply before subtract

Arithmetic Before Comparison

IF A + B * C GT D evaluates B * C, adds A, compares to D. IF GROSS * 0.10 GT LIMIT computes tax amount before threshold test. IF GROSS - DEDUCT LT 0 subtracts after any implied multiply in more complex form—parenthesize net: IF (GROSS - DEDUCT) LT 0. Relational operators never run before arithmetic operands on same expression line are resolved.

text
1
2
3
IF GROSS * TAX-RATE GT MIN-TAX PERFORM APPLY-MIN-TAX END-IF

AND Before OR

Logical precedence causes AND groups to form before OR connects groups. IF A OR B AND C parses as IF A OR (B AND C)—true when A alone, or when both B and C. IF STATUS EQ A OR STATUS EQ B AND GROSS GT 0 may parse as STATUS EQ A OR (STATUS EQ B AND GROSS GT 0)— active status always passes; pending requires positive gross. Intended (STATUS EQ A OR STATUS EQ B) AND GROSS GT 0 needs parentheses. Document intended grouping in comment beside line for auditors.

text
1
2
3
4
5
* Default binding: IF DEPT EQ 10 OR DEPT EQ 20 AND GROSS GT 0 * Intended both depts require gross: IF (DEPT EQ 10 OR DEPT EQ 20) AND GROSS GT 0

NOT Placement

NOT negates the condition that follows or grouped unit IF NOT EOF. IF NOT STATUS EQ A may parse differently than IF STATUS NE A—prefer NE for clarity when equivalent. IF NOT (A GT 0 AND B GT 0) negates entire AND group. Misplaced NOT causes inverted branch logic hard to spot in diff reviews.

Assignment Evaluation Order

Right side of assignment evaluates completely before store into left target. NET = A + B * C computes B * C, adds A, stores into NET. ROUNDED TRUNCATED apply at store step after full right-side evaluation. Multiple assignments on consecutive lines execute top to bottom—no expression across lines unless fields reference prior results.

Left-to-Right at Same Precedence

Operators at same level often associate left to right. 20 - 10 - 2 yields 8 not 12: subtract 10 from 20, then subtract 2. 24 / 6 / 2 yields 2: divide 24 by 6, then by 2. Addition chains left to right similarly. Exponentiation associativity is the common footgun—parenthesize exponents in financial code.

Order in DO WHILE and IF

Condition expression on IF or DO WHILE line evaluates once per entry or iteration per statement rules. Short-circuit evaluation—skipping right side when AND left false—do not rely on undocumented for safety-critical guards; test divisor explicitly before divide even inside AND chain.

Worked Payroll Example

Line: IF GROSS GT LIMIT + ADJ AND STATUS EQ A OR HOLD EQ Y. Step 1: LIMIT + ADJ add. Step 2: GROSS GT sum compare. Step 3: STATUS EQ A compare. Step 4: HOLD EQ Y compare. Step 5: AND binds STATUS EQ A with prior GT result? Actually AND before OR: group (GROSS GT LIMIT + ADJ AND STATUS EQ A) OR HOLD EQ Y. Trace with test values: GROSS 5000, LIMIT 4000, ADJ 500, STATUS P, HOLD Y—GT true, STATUS false, AND false, HOLD true, OR true—branch taken. Without trace, surprise payments occur.

Shop Standards

  1. Parenthesize every mixed AND OR line in production payroll.
  2. Ban ** without parens in standards unless tested.
  3. Require work field when more than three arithmetic operators.
  4. Unit test boundary values after precedence-sensitive change.
  5. Comment intended grouping beside complex IF.

Common Order Mistakes

  • Assuming pure left-to-right across all operators.
  • OR AND mix without parens—wrong eligibility.
  • Subtract multiply order in NET formulas.
  • Exponentiation stack ambiguity.
  • NOT scope unclear—use NE or parens.
  • Copying Excel formula precedence without z/OS test.

Explain It Like I'm Five

Order of evaluation is which math sign goes first when no one put parentheses. Times and divide go before plus and minus. Questions like bigger-than go after the math is done. AND is stickier than OR—it groups before OR unless parentheses say otherwise. Parentheses are the boss—they tell everyone what to do first.

Exercises

  1. Compute 10 + 5 * 2 and (10 + 5) * 2 by hand.
  2. Parse IF A OR B AND C into default grouping.
  3. Rewrite precedence-sensitive IF with full parentheses.
  4. Trace payroll example with five test value sets.
  5. List precedence ranks for * vs + vs GT vs AND.

Quiz

Test Your Knowledge

1. In A + B * C multiplication runs before addition because:

  • * binds tighter than +
  • + always first
  • Random
  • Compile error

2. IF A GT 0 AND B GT 0 OR C GT 0 without parens groups as:

  • (A GT 0 AND B GT 0) OR C GT 0
  • A GT 0 AND (B GT 0 OR C GT 0)
  • All OR first
  • Invalid

3. Exponentiation ** binds:

  • Tighter than multiply and divide
  • Looser than OR
  • Same as EQ
  • Last

4. Parentheses in expression:

  • Override default precedence
  • Are ignored
  • Only for comments
  • JCL only

5. Relational operators GT LT EQ bind:

  • After arithmetic on same expression line
  • Before arithmetic
  • Before **
  • Never
Published
Read time16 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 operator precedence arithmetic relational logicalSources: Broadcom Easytrieve 11.6 Language Reference expressions and conditionsApplies to: Easytrieve order of evaluation