Easytrieve Comparison Expressions

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.

Progress0 of 0 lessons

Relational Operators

Comparison operators and meaning
OperatorMeaningExample
EQEqual toIF STATUS EQ A
NENot equal toIF DEPT NE 999
GTGreater thanIF GROSS GT LIMIT
LTLess thanIF COUNT LT 100
GEGreater than or equalIF AGE GE 18
LELess than or equalIF 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 — Equality

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.

text
1
2
3
4
5
6
7
IF STATUS EQ 'A' PERFORM ACTIVE-PROCESSING END-IF IF PERSNL:DEPT EQ BONUS:DEPT PERFORM MATCH-DEPT END-IF

NE — Not Equal

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.

GT, LT, GE, LE — Ordering

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.

text
1
2
3
4
5
6
7
IF GROSS GT LIMIT BONUS = GROSS * 0.05 END-IF IF SERVICE GE 20 PERFORM LONG-SERVICE END-IF

THRU — Inclusive Ranges

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.

text
1
2
3
4
5
6
7
IF SERVICE EQ 1 THRU 5 PERFORM TRAINEE-RULES END-IF IF REGION EQ 'E' THRU 'M' PERFORM EAST-MIDWEST END-IF

Operands in Comparisons

Common operand pairings
Left operandOperatorRight operandNotes
FieldEQLiteralMost common IF pattern
FieldGTFieldCompare two columns on same record
FieldEQTHRU rangeInclusive low THRU high
Qualified fieldNELiteralPERSNL:STATUS NE X when multi-file

Numeric Comparison and Implied Decimals

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 and Collating Sequence

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.

Comparison vs Class Conditions

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.

Comparing to System Constants

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.

Date and Special 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.

Comparison in DO WHILE

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.

text
1
2
3
4
5
WS-COUNT = 0 DO WHILE WS-COUNT LT 50 PERFORM PROCESS-ROW WS-COUNT = WS-COUNT + 1 END-DO

Common Comparison Mistakes

  • Using = instead of EQ in IF—syntax or wrong semantics.
  • Ignoring trailing spaces on fixed alphabetic compares.
  • THRU range with reversed endpoints—never matches.
  • GT when business rule needs GE—off-by-one at boundary.
  • Comparing FILE packed field before NUMERIC validation.
  • Assuming ASCII sort order on mainframe EBCDIC data.

Explain It Like I'm Five

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.

Exercises

  1. Write IF with EQ testing status literal Y.
  2. Rewrite GE and LE pair as single THRU range.
  3. Compare two fields GROSS and LIMIT with GT.
  4. Explain trailing space impact on NAME EQ literal test.
  5. Add NUMERIC guard before GT on FILE amount.

Quiz

Test Your Knowledge

1. IF STATUS EQ Y tests:

  • Equality between field and literal
  • Assignment to Y
  • Exponentiation
  • File open

2. IF SERVICE EQ 6 THRU 10 is true when SERVICE is:

  • 6 through 10 inclusive
  • Only 6
  • Only 10
  • Greater than 10 only

3. NE means:

  • Not equal
  • Negative
  • New entry
  • No error

4. GT and LT compare:

  • Greater than and less than
  • Get and let
  • Group total
  • Generate table

5. Comparing alphabetic fields uses:

  • Collating sequence for character ordering
  • Numeric subtraction only
  • JCL order
  • Random order
Published
Read time16 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 relational operators EQ NE GT LT GE LE THRUSources: Broadcom Easytrieve 11.6 Language Reference conditional expressionsApplies to: Easytrieve comparison expressions