Comparison expressions ask whether two values stand in a particular relationship—is status equal to active, is gross greater than the limit, is service code between six and ten? Easytrieve answers with relational operators inside IF, ELSE, END-IF, DO WHILE, and related conditional statements. EQ tests equality. NE tests inequality. GT, LT, GE, and LE test ordering. THRU tests inclusive ranges in one compact condition. Unlike assignment, which uses a single equals sign to store a value, comparisons use spelled-out operators beginners must memorize—especially EQ instead of the equals sign from other languages. Alphabetic comparisons follow collating sequence; numeric comparisons respect implied decimals on packed fields. This page explains each operator, operand pairing rules, range syntax, signed comparisons, common payroll patterns, and mistakes that cause silent wrong branches in production batch jobs.
| Operator | Meaning | Example |
|---|---|---|
| EQ | Equal to | IF STATUS EQ A |
| NE | Not equal to | IF DEPT NE 999 |
| GT | Greater than | IF GROSS GT LIMIT |
| LT | Less than | IF COUNT LT 100 |
| GE | Greater than or equal | IF AGE GE 18 |
| LE | Less than or equal | IF DEDUCT LE GROSS |
Broadcom documentation also documents symbolic forms such as = and <> in some contexts, but IF examples overwhelmingly use EQ NE GT LT GE LE spellings. Beginners should standardize on letter operators in new code for consistency with manuals and shop style guides. Mixing symbolic and spelled forms in one program confuses maintenance readers.
EQ tests whether left and right operands have equal value after conversion rules apply. IF STATUS EQ Y branches when the one-byte status field contains Y. IF EMPL-NUM EQ 0 branches on zero employee number—distinct from IF EMPL-NUM ZERO class condition which tests numeric zero property. Compare field to literal, field to field, or field to system constant where grammar allows. Trailing spaces matter on fixed-length alphabetic fields: IF NAME EQ SMITH may fail when NAME holds SMITH followed by spaces unless comparison rules trim or pad per product behavior—test with DISPLAY on suspect data.
1234567IF STATUS EQ 'A' PERFORM ACTIVE-PROCESSING END-IF IF PERSNL:DEPT EQ BONUS:DEPT PERFORM MATCH-DEPT END-IF
NE is the inverse of EQ—condition true when values differ. IF STATUS NE X skips terminated employees. IF DEDUCT-CODE NE 0 processes only rows with deduction codes present. NE pairs naturally with OR for multiple exclusions: IF DEPT NE 10 AND DEPT NE 20 is clearer than double NE in some cases; alternatively IF DEPT EQ 10 OR DEPT EQ 20 with inverted logic in ELSE—choose readability over cleverness.
Ordering operators compare magnitude. GT and LT are strict—equal values fail GT and LT tests. GE and LE include equality—IF COUNT GE 100 passes at exactly one hundred. Payroll threshold logic uses GT frequently: IF GROSS GT LIMIT triggers supplemental processing. Credit limit checks use LT: IF BALANCE LT ZERO flags overdraft when signed fields support negative values. Pair GE with minimum wage rules: IF RATE GE MIN-RATE.
1234567IF GROSS GT LIMIT BONUS = GROSS * 0.05 END-IF IF SERVICE GE 20 PERFORM LONG-SERVICE END-IF
THRU compresses two comparisons into one range condition. IF SERVICE EQ 6 THRU 10 replaces IF SERVICE GE 6 AND SERVICE LE 10 when endpoints are constants. Both endpoints are inclusive—six and ten qualify. Range form works with numeric and alphabetic operands when collating order is meaningful. IF CODE EQ A THRU C includes A, B, and C in alphabetic sequence. Invalid ranges where low endpoint sorts above high endpoint fail or never match depending on operands—code IF CODE EQ Z THRU A only when collating supports intended wrap logic, which is rare; prefer explicit OR lists for non-contiguous codes.
1234567IF SERVICE EQ 1 THRU 5 PERFORM TRAINEE-RULES END-IF IF REGION EQ 'E' THRU 'M' PERFORM EAST-MIDWEST END-IF
| Left operand | Operator | Right operand | Notes |
|---|---|---|---|
| Field | EQ | Literal | Most common IF pattern |
| Field | GT | Field | Compare two columns on same record |
| Field | EQ | THRU range | Inclusive low THRU high |
| Qualified field | NE | Literal | PERSNL:STATUS NE X when multi-file |
Packed P and zoned N fields compare using quantitative values—2.50 GT 2.49 on P 2 fields. Mixing types converts per product rules before compare. Invalid packed sign on FILE field may abend during comparison even when syntax is valid—validate NUMERIC first on untrusted input. Unsigned N fields without decimal positions compare as integers. Comparing computed arithmetic result to literal uses same operators: IF GROSS * 0.10 GT 500 after precedence evaluates multiplication—see mixed expressions page.
Alphabetic A fields compare character by character using collating order—on z/OS typically EBCDIC. Lowercase and uppercase differ unless data is normalized. Blank-filled fixed fields sort after shorter effective values depending on position—NAME with trailing spaces compares differently than varying-length trimmed strings. Case-sensitive shops standardize input to upper case in PROC before compare. THRU on letters requires understanding alphabet order in your environment—not ASCII order from PC editors.
Class conditions like IF FIELD NUMERIC or IF FIELD ZERO are not relational comparisons to a second operand—they test field properties. Combine them with comparisons in logical expressions: IF GROSS NUMERIC AND GROSS GT 0. See boolean concepts for class condition catalog. Comparison expressions always involve relational operator between operands or THRU range form.
Tests against ZERO, SPACE, HIGH-VALUES, and LOW-VALUES use comparison or class forms per documentation. IF FIELD EQ SPACE detects blank-filled alpha fields. IF AMOUNT EQ LOW-VALUES may indicate uninitialized file content—often paired with validation rather than business branching. EOF and DUPLICATE are special constants for input loops—not generic field comparisons.
Display dates in multiple formats compare reliably only when formats align or when converted to internal date representation. DATEVAL routine sets DATEVAL-FLAG; compare flag EQ YES rather than comparing raw date bytes when validation is required. Internal P date fields compare as numeric day offsets—see internal date representation page before comparing MM/DD/YY overlays directly.
DO WHILE WS-COUNT LT 100 repeats while comparison true. DO WHILE STATUS NE X continues until status changes. Re-evaluated each iteration—ensure loop body moves compared fields toward false condition or loop runs forever.
12345WS-COUNT = 0 DO WHILE WS-COUNT LT 50 PERFORM PROCESS-ROW WS-COUNT = WS-COUNT + 1 END-DO
Comparison expressions ask questions about sizes and sameness. EQ asks are these the same? NE asks are they different? GT asks is the left bigger? LT asks is the left smaller? GE and LE allow same or bigger/smaller. THRU asks is the number in the fence between two posts including both posts. Easytrieve uses your yes or no answer to decide whether to run the instructions in the IF block.
1. IF STATUS EQ Y tests:
2. IF SERVICE EQ 6 THRU 10 is true when SERVICE is:
3. NE means:
4. GT and LT compare:
5. Comparing alphabetic fields uses: