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.
| Category | Purpose | Example |
|---|---|---|
| Arithmetic | Compute numeric result | NET = GROSS - DEDUCT |
| Comparison | Test relationship | IF DEPT EQ 100 |
| Logical | Combine conditions | IF A GT 0 AND B LT 99 |
| Class | Test field property | IF ACCT NUMERIC |
| Series (range) | Inclusive range test | IF CODE EQ 10 THRU 20 |
| Mixed | Arithmetic inside comparison | IF GROSS * 0.10 GT LIMIT |
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 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.
123NET-PAY = GROSS - FED-TAX - STATE-TAX BONUS = GROSS * 0.05 ROUNDED FACTOR = RATE ** 2
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.
1234IF STATUS EQ 'A' IF GROSS GT LIMIT IF SERVICE EQ 1 THRU 5 IF EMPL-NUM NE 0
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.
123IF STATUS EQ 'A' AND GROSS GT 1000 IF DEPT EQ 10 OR DEPT EQ 20 IF NOT EOF
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.
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.
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 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.
1234HOLD = (GROSS + BONUS) * TAX-RATE IF (GROSS - DEDUCT) GT 0 AND STATUS EQ 'A' NET = GROSS - DEDUCT END-IF
| Statement form | Expression inside |
|---|---|
| WS-TOTAL = GROSS + BONUS | GROSS + BONUS (arithmetic) |
| IF STATUS EQ Y | STATUS EQ Y (comparison) |
| IF A GT 0 AND B LT 9 | A GT 0 AND B LT 9 (logical + comparison) |
| DO WHILE NOT EOF | NOT EOF (logical + constant) |
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.
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.
1. An Easytrieve expression is:
2. Arithmetic expressions appear in:
3. Logical expressions combine:
4. Comparison expressions test:
5. Mixed expressions often appear in: