Easytrieve Expressions Overview

An expression is the formula inside a statement—the part that calculates or asks a question. TOTAL = GROSS + BONUS contains an arithmetic expression on the right of the equals sign. IF STATUS EQ Y AND GROSS GT 1000 contains logical and comparison expressions inside the condition. Easytrieve does not use a separate expression language like SQL SELECT lists; expressions live inside assignment, IF, ELSE, END-IF, DO WHILE, and related statement forms you already code in JOB activities and PROCs. Operands are fields, literals, and reserved constants like ZERO or SPACE. Operators include arithmetic plus minus asterisk slash, comparison EQ and GT, logical AND OR, and class tests like NUMERIC. Beginners from spreadsheet formulas recognize the pattern immediately; COBOL programmers should note Easytrieve uses infix notation more freely in assignment. This overview maps expression categories, shows where each appears, explains how types interact, and points to dedicated pages for arithmetic, logical, comparison, mixed, nested, precedence, and parentheses depth.

Progress0 of 0 lessons

Expression Categories

Three families beginners use daily
CategoryPurposeExample
ArithmeticCompute numeric resultNET = GROSS - DEDUCT
ComparisonTest relationshipIF DEPT EQ 100
LogicalCombine conditionsIF A GT 0 AND B LT 99
ClassTest field propertyIF ACCT NUMERIC
Series (range)Inclusive range testIF CODE EQ 10 THRU 20
MixedArithmetic inside comparisonIF GROSS * 0.10 GT LIMIT

Operands: What Expressions Combine

Fields are the most common operands—GROSS, WS-TOTAL, PERSNL:NAME. Literals supply fixed values: numeric 1000, alphanumeric Y, hexadecimal X'00'. System constants ZERO, SPACE, HIGH-VALUES, and LOW-VALUES act as operands in MOVE and comparison contexts. Parentheses group subexpressions when precedence would otherwise compute in the wrong order. Operands must be compatible with the operator: arithmetic operators expect numeric operands unless product rules convert alphabetic digits; comparison operators match types per field definitions; logical connectors join conditions, not raw numeric fields without a relational test.

Arithmetic Expressions

Arithmetic expressions use + - * / and ** exponentiation between numeric operands. They appear primarily on the right side of assignment: BONUS = GROSS * 0.10. Quantitative fields—those with decimal positions on packed or zoned definitions—participate in signed arithmetic. ROUNDED and TRUNCATED keywords on assignment affect how results land in the target field. See the arithmetic expressions page for operator details, division remainder behavior, MOD alternatives, and packed decimal alignment rules.

text
1
2
3
NET-PAY = GROSS - FED-TAX - STATE-TAX BONUS = GROSS * 0.05 ROUNDED FACTOR = RATE ** 2

Comparison Expressions

Comparison expressions test how two values relate. Relational operators include EQ equal, NE not equal, GT greater than, LT less than, GE greater or equal, LE less or equal. Compare field to field, field to literal, or field to constant. Series conditions use THRU for inclusive ranges: IF SERVICE EQ 6 THRU 10 passes for 6, 7, 8, 9, and 10. Alphabetic comparisons use collating sequence rules. Date fields may need DATEVAL or internal date formats for reliable comparisons—see date data type pages.

text
1
2
3
4
IF STATUS EQ 'A' IF GROSS GT LIMIT IF SERVICE EQ 1 THRU 5 IF EMPL-NUM NE 0

Logical Expressions

Logical expressions connect two or more conditions with AND or OR. AND requires every connected condition true; OR requires at least one true. NOT negates a condition in supported forms per release documentation. Evaluation order matters: AND groups bind before OR unless parentheses change grouping—see order of evaluation and parentheses pages. Class conditions like IF FIELD NUMERIC are themselves conditions that logical connectors combine: IF ACCT NUMERIC AND BALANCE GT 0.

text
1
2
3
IF STATUS EQ 'A' AND GROSS GT 1000 IF DEPT EQ 10 OR DEPT EQ 20 IF NOT EOF

Class and Special Conditions

Beyond relational comparisons, class conditions test properties: NUMERIC, ALPHABETIC, ZERO, POSITIVE, NEGATIVE, and others documented for your release. EOF and DUPLICATE constants appear in input loop conditions. DATEVAL sets a flag field rather than acting as inline boolean in all contexts—boolean concepts page covers flag patterns. Expressions in Easytrieve are not a separate boolean type; conditions evaluate at runtime to true or false for branching.

Where Expressions Appear

  • Assignment: TARGET = expression assigns computed or copied value.
  • IF and ELSE: condition expression controls block execution.
  • DO WHILE: condition re-evaluated each loop iteration.
  • WHEN on some report contexts: conditional printing per documentation.
  • MASK and edit contexts: display formatting related to numeric content.

Expressions do not appear as standalone lines—the surrounding statement provides context. A line reading only GROSS + BONUS is incomplete; WS-TOTAL = GROSS + BONUS is valid assignment.

Type Conversion in Expressions

Mixing zoned N, packed P, binary B, and floating U or I triggers product conversion rules. Assigning arithmetic result into packed target aligns implied decimals. Comparing alphabetic field to numeric literal may compile with conversion or fail—match shop standards and test. Invalid packed data from FILE buffers causes data exceptions during arithmetic even when expression syntax is correct. Validate FILE numerics with class tests before they enter expressions.

Nested and Mixed Expressions

Nested expressions place operators inside grouped subexpressions: NET = (GROSS - TAX) * RATE. Mixed expressions combine arithmetic with comparison in IF: IF GROSS - DEDUCT LT 0. Parentheses clarify intent when precedence rules would otherwise apply multiplication before subtraction or bind AND before OR. Deep nesting hurts readability—intermediate W fields with clear names often beat ten-level formulas in maintenance-sensitive payroll code.

text
1
2
3
4
HOLD = (GROSS + BONUS) * TAX-RATE IF (GROSS - DEDUCT) GT 0 AND STATUS EQ 'A' NET = GROSS - DEDUCT END-IF

Expressions vs Complete Statements

Statement wraps expression
Statement formExpression inside
WS-TOTAL = GROSS + BONUSGROSS + BONUS (arithmetic)
IF STATUS EQ YSTATUS EQ Y (comparison)
IF A GT 0 AND B LT 9A GT 0 AND B LT 9 (logical + comparison)
DO WHILE NOT EOFNOT EOF (logical + constant)

Beginner Mental Model

Think of expressions as the math or question inside a sentence. The statement is the full sentence telling Easytrieve what to do with the answer. Arithmetic expressions produce numbers for storage. Comparison and logical expressions produce branch decisions—no stored boolean variable unless you set a flag field based on the outcome. That model aligns with how Broadcom training manuals teach payroll IF blocks and running totals in assignment statements.

Common Expression Mistakes

  • Using = in IF instead of EQ—assignment versus comparison syntax.
  • Arithmetic on unvalidated FILE packed fields after bad READ.
  • AND OR precedence surprises—use parentheses when mixing connectors.
  • Comparing alphabetic dates without DATEVAL or internal format.
  • Expression line without assignment or IF wrapper—syntax error.
  • Expecting boolean variable from IF condition without flag assignment.

Explain It Like I'm Five

Expressions are the math or question inside your instruction. Add two numbers—that is an arithmetic expression. Ask if the door color is red—that is a comparison expression. Ask if the door is red and the window is open—that is a logical expression combining two questions. Easytrieve needs the full instruction: put the answer in this box, or if the question is yes do this block. The expression alone is just the math or question floating without instructions.

Exercises

  1. Label each operand and operator in NET = GROSS * 0.10 + FLAT.
  2. Rewrite IF A GT 0 AND B GT 0 OR C GT 0 with parentheses for two different meanings.
  3. Identify arithmetic versus comparison parts in IF GROSS GT LIMIT + 100.
  4. List three statement types that contain expressions.
  5. Add NUMERIC class test before arithmetic on FILE amount field.

Quiz

Test Your Knowledge

1. An Easytrieve expression is:

  • Operands combined with operators to produce a value or condition
  • Only a JCL DD statement
  • Only a FILE definition
  • Only a report TITLE line

2. Arithmetic expressions appear in:

  • Assignment statements like TOTAL = A + B
  • FILE statement only
  • JCL only
  • Comments only

3. Logical expressions combine:

  • Relational or class conditions with AND OR NOT
  • Only FILE names
  • Only MASK characters
  • Only DD names

4. Comparison expressions test:

  • Relationship between two values or a value and constant
  • JCL return code only
  • Compile options
  • Tape label only

5. Mixed expressions often appear in:

  • IF statements combining arithmetic results with comparisons
  • FILE only
  • Never valid
  • MACRO only
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 expression grammar in assignment and IF statementsSources: Broadcom Easytrieve 11.6 Language Reference, Getting Started, Programming GuideApplies to: Easytrieve expressions overview