Easytrieve Mixed Expressions

Real programs rarely keep arithmetic, comparison, and logical operators in separate boxes. Mixed expressions combine them: compute ten percent of gross and test whether it exceeds the limit in one IF line; subtract deductions from gross and branch when net is negative; connect a numeric validation with AND to a range test on a summed field. Mixed expressions are powerful and error-prone—operator precedence decides whether multiplication runs before greater-than, whether AND binds before OR, and whether your payroll exception fires on the wrong records. Beginners who write IF A + B GT C * D without parentheses rely on rules they have not memorized. This page teaches mixed forms in assignment and conditions, precedence interactions, parentheses as documentation, intermediate work fields as clarity tools, and production patterns that balance compact syntax with audit-friendly readability.

Progress0 of 0 lessons

What Makes an Expression Mixed

Mixed expression patterns
PatternExampleOperator families
Arithmetic in IFIF GROSS * 0.10 GT 500Arithmetic + comparison
Arithmetic both sidesIF A + B GT C + DArithmetic + comparison
Logical + arithmetic compareIF A GT 0 AND B + C GT 10Logical + arithmetic + comparison
Assignment formulaNET = GROSS - TAX - FICAArithmetic in assignment
Grouped mixed IFIF (A - B) GT 0 AND STATUS EQ AAll three with parentheses

Arithmetic Inside Comparisons

The most common mixed form puts arithmetic on one or both sides of a relational operator. IF GROSS * 0.10 GT LIMIT multiplies gross by literal percentage then compares product to limit field. Multiplication binds before GT—equivalent to computing tax amount mentally then asking if it exceeds limit. IF GROSS - DEDUCT LT 0 detects negative net without assigning NET first—useful for exception DISPLAY before correction logic runs.

text
1
2
3
4
5
6
7
IF GROSS * 0.10 GT LIMIT PERFORM BONUS-TIER-2 END-IF IF GROSS - TOTAL-DEDUCT LT 0 DISPLAY 'NEGATIVE NET' EMPL-NUM END-IF

Arithmetic on Both Sides

IF REG-HRS + OT-HRS GT STD-HRS + OT-CAP compares total hours worked against combined standard plus overtime ceiling. Each side evaluates independently before relational test. Field sizes must accommodate intermediate arithmetic on each side—overflow on left side may abend before compare executes. When formulas grow beyond two terms per side, use W hold fields: TOTAL-HRS = REG-HRS + OT-HRS; CAP = STD-HRS + OT-CAP; IF TOTAL-HRS GT CAP.

Logical Connectors with Mixed Conditions

IF GROSS NUMERIC AND GROSS * 0.05 GT 100 combines class condition with arithmetic comparison—both must pass. IF DEPT EQ 10 OR GROSS + BONUS GT 5000 mixes OR with arithmetic on right alternative—precedence binds AND before OR when both appear; see order of evaluation. Parentheses clarify intent: IF (DEPT EQ 10 OR DEPT EQ 20) AND GROSS GT LIMIT requires department match and gross threshold.

text
1
2
3
4
5
6
7
IF GROSS NUMERIC AND GROSS * TAX-RATE GT MIN-TAX PERFORM APPLY-TAX END-IF IF (STATUS EQ 'A' OR STATUS EQ 'P') AND GROSS GT 0 PERFORM PAY-CYCLE END-IF

Mixed Assignment Expressions

Assignment is mixed when right side combines multiple arithmetic operators: NET = GROSS - FED - STATE - FICA. Subtraction associates left to right unless parentheses group terms. NET = (GROSS - FED) * ADJ-RATE mixes subtract and multiply—multiply binds tighter unless grouped. ROUNDED and TRUNCATED on assignment apply to final store into target, not to subexpressions individually—compute HOLD with explicit rounding if policy requires rounded intermediate tax before subtracting from gross.

text
1
2
NET = GROSS - FED-TAX - STATE-TAX - FICA ADJ = (BASE + BONUS) * FACTOR ROUNDED

Precedence in Mixed Expressions

Typical precedence from highest to lowest: exponentiation, multiply and divide, add and subtract, relational comparisons, NOT, AND, OR. Expression IF A + B * C GT D multiplies B and C before adding A and before comparing to D. Expression IF A GT 0 AND B GT 0 OR C GT 0 groups AND before OR. When in doubt, parenthesize—auditors and your future self thank you. Full precedence tables live on order of evaluation and parentheses pages.

Parentheses in Mixed Forms

Parentheses override default precedence and document business grouping. IF (GROSS - DEDUCT) GT LIMIT compares net to limit, not gross to limit after unrelated subtract parsing. IF GROSS GT (LIMIT + ADJ) adds adjustment to limit before compare. Nested parentheses allowed within reason—IF ((A + B) * C) GT D. Excessive nesting signals refactor to PROC or hold variables.

Intermediate Work Fields Pattern

Production maintainers often ban mixed IF lines beyond two operators. Pattern: compute in assignment, compare in simple IF. TAX-HOLD = GROSS * TAX-RATE ROUNDED. IF TAX-HOLD GT MAX-TAX. Benefits: DISPLAY TAX-HOLD in debug, reuse TAX-HOLD in PUT, single rounding point. Mixed expression still exists across two statements—clarity improves without changing business result when order matches.

text
1
2
3
4
5
TAX-HOLD = GROSS * TAX-RATE ROUNDED IF TAX-HOLD GT MAX-TAX TAX-HOLD = MAX-TAX END-IF NET = GROSS - TAX-HOLD

Mixed Types in One Expression

Mixing packed, zoned, and literals triggers conversion before arithmetic and comparison. IF N-FIELD + P-FIELD GT 1000 converts per product rules—usually succeeds when fields are valid numeric. Mixing alphabetic with numeric without conversion fails compile or produces nonsense—do not add NAME + 1. DATE fields compared after arithmetic require consistent representation—prefer validated internal dates for mixed date math.

Mixed Expressions in DO WHILE

DO WHILE WS-COUNT LT MAX AND GROSS GT 0 continues while both mixed conditions hold. Arithmetic in loop condition re-evaluates each iteration—changing GROSS inside loop affects next test. Avoid expensive mixed formulas in tight loops when simple counter LT suffices.

Report Context Mixed Usage

JOB assignment mixed expressions feed report fields before PRINT. Report LINE and SUM use field values after assignment—not inline IF arithmetic in LINE list beyond field names and literals per report grammar. Keep heavy mixed math in JOB; report displays results.

Testing Mixed Expressions

  1. Trace boundary values—exactly at LIMIT, zero gross, max hours.
  2. DISPLAY intermediate holds when IF branch surprises.
  3. Verify rounding policy on tax mixed lines matches audit spreadsheet.
  4. Test OR and AND mixed lines with parentheses both ways if unsure.
  5. FLDCHK on FILE fields before they enter mixed IF arithmetic.

Common Mixed Expression Mistakes

  • Assuming left-to-right evaluation for all operators.
  • Missing parentheses on IF GROSS - DEDUCT LT LIMIT + ADJ.
  • AND OR mixed without grouping—wrong employees paid.
  • Overflow in subexpression before comparison—abend not false branch.
  • ROUNDED needed on assignment but crammed into IF compare line.
  • One-line mixed IF too dense for production support.

Explain It Like I'm Five

Mixed expressions do math and ask questions in the same sentence. If ten percent of your allowance is bigger than the piggy bank limit, you get a warning—that is multiply and greater-than together. If you are tall enough and your age plus bonus years is over ten, you ride—that is AND with plus and compare. Parentheses are like saying do this math part first in a quiet whisper before the loud question.

Exercises

  1. Rewrite IF GROSS * 0.10 GT LIMIT using TAX-HOLD work field.
  2. Add parentheses to change meaning of A + B GT C + D.
  3. Write mixed IF with AND, arithmetic, and NUMERIC class test.
  4. Explain evaluation order in IF A + B * 2 GT 100.
  5. Identify all operator families in IF (A - B) GT 0 AND C EQ 1.

Quiz

Test Your Knowledge

1. IF GROSS * 0.10 GT LIMIT contains:

  • Arithmetic subexpression compared with GT
  • Only logical AND
  • Only assignment
  • FILE definition

2. In mixed expressions multiplication binds before GT meaning:

  • GROSS * 0.10 evaluates before comparison to LIMIT
  • GT runs before multiply
  • Random order
  • Compile error always

3. NET = GROSS - TAX - FICA is:

  • Arithmetic assignment expression
  • Pure comparison
  • Logical OR
  • THRU range

4. IF (GROSS - DEDUCT) LT 0 uses parentheses to:

  • Force subtraction before LT comparison
  • Comment code
  • Define FILE
  • Set JCL

5. IF A GT 0 AND B + C GT 10 mixes:

  • Logical AND with arithmetic and comparison
  • Only THRU
  • Only EQ
  • Only NOT
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 mixed arithmetic relational logical expression precedenceSources: Broadcom Easytrieve 11.6 Language Reference expressions and conditionsApplies to: Easytrieve mixed expressions