Easytrieve Parentheses

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.

Progress0 of 0 lessons

Syntax Rules

Parenthesis basics
RuleDetail
Matching pairsEach ( requires matching ) on same expression
NestingInner ( ) evaluates before outer groups
No empty pairs() without operands is invalid
SpacingSpaces around parens optional per shop style
Not for commentsUse * comment lines—not parens—for remarks

Arithmetic Grouping

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.

text
1
2
3
NET = (GROSS - FED - STATE) * FX-RATE PCT = (PART / TOTAL) * 100 ADJ = BASE + (BONUS * FACTOR)

Comparison Grouping

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.

text
1
2
3
IF (REG-HRS + OT-HRS) GT STD-HRS PERFORM OT-REVIEW END-IF

Logical Grouping

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.

text
1
2
3
4
IF (DEPT EQ 100 OR DEPT EQ 200 OR DEPT EQ 300) AND GROSS GT 0 PERFORM CORP-BONUS END-IF

Nested Parentheses

((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.

Redundant Parentheses for Documentation

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 vs Nested IF

Parentheses group on one expression line. Nested IF stacks blocks:

text
1
2
3
4
5
IF 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.

Common Parenthesis Mistakes

  • Missing close paren—compile error at line or next line.
  • Wrong group changes bonus eligibility—logic bug.
  • Omitting parens on OR AND mix—precedence bug.
  • Parenthesis around assignment target left side—invalid NET = (GROSS).
  • Spreadsheet paste without paren audit.
  • Deep nest instead of WS-HOLD fields.

Review Checklist

  1. Count ( and ) on each complex line—must match.
  2. Trace one true and one false test case after change.
  3. Compare with flattened work-field version for same result.
  4. Comment intended English meaning beside line.
  5. Peer review mixed logical lines mandatory in financial modules.

Explain It Like I'm Five

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.

Exercises

  1. Add parens to NET = GROSS - DEDUCT * RATE for (GROSS - DEDUCT) * RATE.
  2. Fix IF A OR B AND C with parens for (A OR B) AND C.
  3. Find compile error from intentional missing ).
  4. Flatten ((A+B)*C)-D to two assignment lines.
  5. Write audit comment for parenthesized IF line.

Quiz

Test Your Knowledge

1. Parentheses in expression (A + B) * C force:

  • Addition before multiplication
  • Multiplication before addition
  • Compile skip
  • JCL change

2. Unmatched parenthesis in source causes:

  • Compile error
  • Silent wrong result
  • Faster run
  • Ignore

3. IF (STATUS EQ A OR STATUS EQ B) AND GROSS GT 0 uses parens to:

  • Group OR before AND
  • Comment code
  • Define FILE
  • Set MASK

4. Extra parentheses around single field A + B:

  • Valid but unnecessary unless documenting
  • Always illegal
  • Changes value
  • Doubles A

5. Nested parentheses ((A + B) * C):

  • Allowed for explicit inner and outer groups
  • Never allowed
  • JCL only
  • Report only
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 parenthesis grouping in expressionsSources: Broadcom Easytrieve 11.6 Language Reference expressionsApplies to: Easytrieve parentheses in expressions