Easytrieve Boolean Concepts

Modern languages offer a boolean type—true or false in one keyword. Easytrieve predates that style. Instead, boolean logic lives in conditional expressions inside IF, ELSE, END-IF, DO WHILE, and END-DO statements. A condition asks a yes-or-no question: Is SERVICE greater than ten? Is STATUS equal to Y? Is EMPL-NUM NUMERIC? The answer determines whether statements execute or loops continue. Flags in one-byte character fields, bit positions in binary halfwords, and routine result fields like DATEVAL-FLAG YES or NO all play boolean roles without a BOOL letter on DEFINE. Beginners from Java or Python must shift mindset: you do not assign true to a variable—you branch when a comparison succeeds. This page teaches condition types, AND OR evaluation order, flag storage patterns, and how boolean thinking connects to payroll IF blocks in Broadcom training examples.

Progress0 of 0 lessons

No Dedicated Boolean Type

DEFINE field-length table lists A, M, K, N, P, B, U, and I. None is boolean. You cannot declare ACTIVE-BOOL as type BOOL with values TRUE and FALSE. Instead, define ACTIVE-FLAG as A 1 and compare IF ACTIVE-FLAG EQ Y. Or use N 1 0 with zero meaning false and one meaning true in shop convention. The compiler evaluates conditions at runtime; storage is always another data type underneath.

IF Statement Structure

IF wraps conditional execution. When the condition is true, statements between IF and ELSE or END-IF run. Optional ELSE provides false branch. END-IF closes the block—nesting requires balanced END-IF for each IF. Missing END-IF is a frequent compile error in indented source editors that hide structure.

text
1
2
3
4
5
6
7
8
9
IF SERVICE GT 14 PERFORM BONUS-CALC END-IF IF SERVICE GT 19 BONUS = 2000 ELSE BONUS = 1000 END-IF

Condition Categories

Simple and extended condition types
Condition typeExampleMeaning
RelationalIF DEPT EQ 'ACC'Field equals literal or other field
Series (THRU)IF SERVICE EQ 6 THRU 10Value in inclusive range
ClassIF EMPL-NUM NUMERICField content passes class test
Combined ANDIF STATUS EQ 'A' AND GROSS GT 0All parts must be true
Combined ORIF REGION EQ 'E' OR REGION EQ 'W'Any part true suffices

Relational Operators

Compare fields to literals or other fields with EQ equal, NE not equal, LT less than, GT greater than, LE less or equal, GE greater or equal. Spelling out EQ instead of equals sign is Easytrieve tradition—readable in column-oriented listings. Compare like types when possible: numeric to numeric, character to quoted literal. Mixing types may invoke conversion rules that surprise beginners—test boundary values in FLDCHK debug runs.

AND and OR Evaluation Order

Broadcom documentation states AND-connected conditions evaluate before OR groups. Within an AND chain, all must be true for the chain to succeed. Within OR, any true condition makes the OR group true. Parentheses in some expression contexts clarify intent—when in doubt, split complex logic into nested IF blocks or named PROCs for auditability. Operations teams reviewing payroll exceptions prefer readable nested IF over single line with four AND connectors.

text
1
2
3
4
5
6
7
IF EMPL-NUM NUMERIC AND EMPL-NUM GT 15555 PRINT EXCEPTION-RPT END-IF IF REGION EQ 'N' OR REGION EQ 'S' OR REGION EQ 'E' WS-ZONE = 'COASTAL' END-IF

DO WHILE Loops

DO WHILE condition repeats a block while condition stays true—boolean logic identical to IF expression grammar. Increment counters inside the loop and ensure condition eventually becomes false to avoid infinite batch jobs consuming CPU until operators cancel. Combine with GOTO and END-DO per program style guides at your site.

Flag Fields as Pseudo-Booleans

Single-character flags are the closest storage analog to boolean. ACTIVE A 1 holds Y or N. ERROR-FLAG A 1 holds space or E. PROCESS-IND N 1 0 holds 0 or 1. Assignment sets flag; IF tests flag. Multiple flags sometimes pack into one binary B field with bit masks—each bit acts as independent boolean at the hardware level. Choose character flags when humans read dumps; choose bits when interfacing binary APIs.

Flag storage patterns
PatternDEFINE exampleTrue test
Y/N characterVALID-FLAG W 1 AIF VALID-FLAG EQ 'Y'
Numeric 0/1DONE-IND W 1 N 0IF DONE-IND EQ 1
Routine resultDATEVAL-FLAG W 3 AIF DATEVAL-FLAG EQ 'YES'
Bit in binarySTATUS W 2 BAfter AND mask, test bit field

Class Conditions

Class conditions test field content category without comparing to a specific value. NUMERIC asks whether characters are valid digits for numeric conversion. ALPHABETIC and related class tests appear in validation before arithmetic. Use class conditions as guards—IF ACCT NUMERIC AND ACCT GT 0 prevents S0C7 on alphabetic garbage in account fields.

THRU Range Conditions

IF SERVICE EQ 6 THRU 10 assigns vacation hours only when service years fall in band six through ten inclusive. THRU replaces multiple OR comparisons for contiguous numeric ranges. Boundaries are inclusive on both ends per training manual examples. Off-by-one errors happen when developers use LT and GT instead of THRU without aligning endpoints.

NOT and Negation

Negate conditions with NE not equal or by restructuring IF ELSE branches. Some extended condition forms support NOT connector in logical expressions per release documentation. When negation grows confusing, prefer positive IF with clear ELSE over double negatives that confuse maintainers during midnight incident response.

Boolean Logic vs Bit Logic

IF conditions are program-flow boolean. AND OR XOR on assignment with hex masks are bit-level boolean on bytes—different layer. IF STATUS-FLAG EQ Y is flow control. F1 = F2 AND X'FFFE' clears bit zero in a halfword. Both are boolean in computer science terms but serve different purposes. See bit fields and hex values pages for mask layer.

Common Boolean Mistakes

  • Comparing Y flag to numeric 1 without conversion.
  • Assuming uninitialized A flag is N—it may be space or LOW-VALUES.
  • Complex AND OR without understanding evaluation order.
  • Using GT on character fields expecting numeric sort order.
  • Forgetting END-IF on nested IF blocks.

Explain It Like I'm Five

Boolean is asking yes-or-no questions. Is it raining? If yes, take an umbrella. Easytrieve does not have a special true-false coin in your pocket—it asks questions about boxes labeled with field names. Is the box labeled SERVICE bigger than ten? If yes, do the bonus steps. Y and N stickers on a one-letter box are the closest thing to a true-false coin you can store.

Exercises

  1. Write IF with ELSE setting BONUS 2000 or 1000 based on SERVICE GT 19.
  2. Combine two conditions with AND for numeric validation plus threshold.
  3. Define Y/N flag and test with IF before PRINT.
  4. Rewrite three OR region tests as one THRU if regions were numeric codes 1-3.
  5. Explain difference between IF flag EQ Y and bit AND mask testing.

Quiz

Test Your Knowledge

1. Easytrieve has a native BOOLEAN data type letter on DEFINE:

  • False—logic uses IF conditions on fields
  • True—type Y
  • True—type L
  • Only in SCREEN

2. Combined conditions with AND are true when:

  • All connected conditions are true
  • Any one condition is true
  • Never
  • Only at compile time

3. A one-byte flag field is often defined as:

  • A 1 or N 1 with Y/N values
  • P 10 2
  • I 8 only
  • Cannot define flags

4. IF SERVICE EQ 6 THRU 10 is a:

  • Field series (range) condition
  • Arithmetic assignment
  • REPORT LINE
  • FILE statement

5. DATEVAL-FLAG set to YES means:

  • Date field passed validation
  • Compile error
  • EOF reached
  • File not found
Published
Read time13 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve IF DO WHILE conditional expressions AND OR THRUSources: CA-Easytrieve Plus 6.4 Application Guide conditional expressions, Broadcom Easytrieve 11.6 programmingApplies to: Easytrieve conditional logic and flag patterns