Parentheses are the override switch for operator precedence. Wrap a subexpression in open and close parentheses to say evaluate this part first before applying outer operators. Without them, Easytrieve follows default binding—multiply before add, AND before OR, arithmetic before greater-than. With them, you control payroll logic explicitly and show auditors exactly what you meant. Parentheses do not create new variables; they only group evaluation on one line. Every open parenthesis requires a matching close; editors and compilers catch imbalance, but merged maintenance decks still ship typos. This page covers arithmetic grouping, logical grouping, nested pairs, redundant parens for documentation, matching rules, contrast with nested IF blocks, and shop standards that require parentheses on every mixed logical condition in production financial code.
| Rule | Detail |
|---|---|
| Matching pairs | Each ( requires matching ) on same expression |
| Nesting | Inner ( ) evaluates before outer groups |
| No empty pairs | () without operands is invalid |
| Spacing | Spaces around parens optional per shop style |
| Not for comments | Use * comment lines—not parens—for remarks |
NET = (GROSS - DEDUCT) * RATE forces subtraction before multiply. Without parens NET = GROSS - DEDUCT * RATE may multiply DEDUCT * RATE first if multiply binds tighter—changing net pay. AVG = TOTAL / (COUNT + ADJ) puts add in denominator group. TAX = GROSS * (RATE + SURCHARGE) adds rate components before multiply. When formula mirrors spreadsheet cell, replicate spreadsheet parens exactly—do not assume Excel and Easytrieve share precedence quirks for exponentiation.
123NET = (GROSS - FED - STATE) * FX-RATE PCT = (PART / TOTAL) * 100 ADJ = BASE + (BONUS * FACTOR)
IF (GROSS - DEDUCT) LT 0 compares net sign. IF (A + B) GT (C + D) groups both sides before relational test. IF GROSS GT (LIMIT + BUFFER) adds tolerance to limit inside parens before compare to gross. Comparison operators sit outside groups once inner arithmetic completes.
123IF (REG-HRS + OT-HRS) GT STD-HRS PERFORM OT-REVIEW END-IF
IF (STATUS EQ A OR STATUS EQ P) AND GROSS GT 0 is the canonical pattern fixing AND-before-OR surprise. IF DEPT EQ 10 OR (DEPT EQ 20 AND GROSS GT 5000) restricts second department with gross guard while first department passes regardless—parentheses document asymmetric rules. NOT with parens: IF NOT (EOF) or IF NOT (STATUS EQ X AND TYPE EQ Y) negates entire grouped condition.
1234IF (DEPT EQ 100 OR DEPT EQ 200 OR DEPT EQ 300) AND GROSS GT 0 PERFORM CORP-BONUS END-IF
((A + B) * C) - D uses two levels—inner add, multiply, outer subtract. Deeper nesting compiles but hurts readability—flatten to work fields when third level adds no clarity. Count pairs from inside out during code review: open count must equal close count at each nesting level.
NET = (GROSS) - (TAX) adds no precedence change but may satisfy shop style requiring parens around each operand in sensitive formulas. IF (GROSS GT LIMIT) redundant when single comparison—still used in some audit templates. Balance policy versus noise—too many redundant parens obscure structure.
Parentheses group on one expression line. Nested IF stacks blocks:
12345IF STATUS EQ 'A' IF GROSS GT LIMIT PERFORM BONUS END-IF END-IF
Equivalent logical intent may use IF STATUS EQ A AND GROSS GT LIMIT without nested IF— choose based on readability and whether intermediate actions differ per level.
Parentheses are little hoops that say do this part first. In 2 + 3 * 4 you multiply first unless you write (2 + 3) * 4—then add inside hoops first. For questions, hoops tell which part of the question to answer before combining with AND or OR. Missing a hoop confuses everyone including the computer.
1. Parentheses in expression (A + B) * C force:
2. Unmatched parenthesis in source causes:
3. IF (STATUS EQ A OR STATUS EQ B) AND GROSS GT 0 uses parens to:
4. Extra parentheses around single field A + B:
5. Nested parentheses ((A + B) * C):