Easytrieve AND Operator

AND combines conditions so every test must pass before Easytrieve executes the IF branch. IF STATUS EQ ACTIVE AND BALANCE GT 0 selects active accounts with money. IF AGE GE 18 AND AGE LE 65 defines a working-age band. IF REGION EQ EAST AND SALES GT QUOTA flags eastern reps who exceeded quota. Without AND you would need nested IF blocks or duplicate processing—AND keeps compound business rules on one readable line. AND differs from OR: OR passes when any condition succeeds; AND demands all. Precedence matters when mixing AND with OR—parentheses clarify intent. NOT negates individual conditions inside AND chains. Beginners write OR when policy requires every criterion—missing fraud checks when only one of three flags should block payment. This page teaches AND syntax, truth tables, banded range patterns, precedence with OR and NOT, nested IF alternatives, performance considerations on large files, and testing compound conditions in Easytrieve batch jobs.

Progress0 of 0 lessons

AND in Conditional Expressions

AND appears between boolean subexpressions in IF, ELSE-IF, DO WHILE, and WHILE constructs. Each side can be a relational test, another AND chain, or a parenthesized group. IF DEPT EQ 100 AND PAY-TYPE EQ SALARY AND GROSS GT 50000 selects high earners in department 100 on salary pay type—all three must hold.

text
1
2
3
4
5
6
7
8
JOB INPUT EMPLOYEE IF STATUS EQ 'A' AND BALANCE GT 0 PRINT ACTIVE-POSITIVE-RPT END-IF IF AGE GE 18 AND AGE LE 65 PRINT WORKING-AGE-RPT END-IF

AND Truth Table

Two-condition AND outcomes
Condition ACondition BA AND B
TrueTrueTrue—IF branch runs
TrueFalseFalse—IF branch skipped
FalseTrueFalse—IF branch skipped
FalseFalseFalse—IF branch skipped

AND Versus OR

OR widens selection—IF DEPT EQ 10 OR DEPT EQ 20 includes either department. AND narrows—IF DEPT EQ 10 AND STATUS EQ ACTIVE includes only active department-ten employees. Policy stating must be active and in department ten requires AND. Policy stating department ten or twenty requires OR. Mixing them without parentheses causes subtle bugs: IF A OR B AND C may parse as A OR (B AND C) or (A OR B) AND C depending on language rules—parentheses remove ambiguity.

Banded Ranges With AND

Numeric windows combine GE and LE with AND: IF SCORE GE 60 AND SCORE LE 79 for passing band C. Date windows: IF EFF-DATE GE START-DATE AND EFF-DATE LE END-DATE for open period. Amount tiers: IF AMT GE 100 AND AMT LE 499 for mid-tier discount. EQ THRU can express some ranges more compactly, but AND with GE and LE handles field-to-field bounds when START-DATE and END-DATE are variables not constants.

text
1
2
3
4
5
6
7
8
JOB INPUT SALES IF REGION EQ 'E' AND UNITS GT QUOTA PRINT EAST-OVER-RPT END-IF IF TRAN-DATE GE PERIOD-START AND TRAN-DATE LE PERIOD-END PRINT IN-PERIOD-RPT END-IF

Precedence With OR and NOT

Standard boolean precedence treats AND tighter than OR. IF A OR B AND C often means A OR (B AND C)—verify against Broadcom documentation for your release. When in doubt, write IF (A OR B) AND C explicitly. NOT applies to the immediately following condition unless grouped: IF NOT STATUS EQ CLOSED AND BALANCE GT 0 negates only the status test. IF NOT (STATUS EQ CLOSED OR BALANCE LE 0) negates the whole OR group—De Morgan patterns help rewrite complex logic clearly.

Chaining Multiple AND Conditions

IF A AND B AND C AND D is valid for four independent tests. Readability degrades beyond three or four—extract to a W flag field: WS-ELIGIBLE = YES after a PROC evaluates rules, then IF WS-ELIGIBLE EQ YES. Audit trails benefit from named flags explaining why a record qualified. Long AND chains also complicate unit testing—each condition needs boundary cases.

AND With Field Comparisons

Both operands in each relational test can be fields or literals. IF CURR-BAL LE LIMIT AND CURR-BAL GT 0 selects positive balances within limit. IF SHIP-DATE GE ORDER-DATE AND SHIP-DATE LE DUE-DATE validates on-time shipment window. Type compatibility applies to each test independently—one AND branch comparing dates and another comparing packed amounts is normal.

Nested IF Versus AND

Nested IF STATUS EQ ACTIVE with inner IF BALANCE GT 0 behaves like AND for positive balance active accounts. AND form is flatter and often preferred in code reviews. Nested form helps when inner block is large and outer failure should skip expensive work—though short-circuit evaluation is compiler-dependent; do not rely on side-effect ordering without documentation.

Testing AND Logic

  1. Test each condition false alone while others true—IF must fail.
  2. Test all conditions true—IF must pass.
  3. Test boundary values on GE and LE pairs in banded AND.
  4. Verify parentheses groups with mixed AND and OR.
  5. Compare record counts against SQL WHERE with identical AND logic.

Common AND Mistakes

  • Using OR when policy requires every condition—should be AND.
  • Missing parentheses with mixed AND and OR.
  • Assuming chained relational IF A LT B LT C works—use AND instead.
  • Negating wrong subexpression with NOT.
  • Overlong AND chains without intermediate flag fields.
  • Comparing incompatible types in one branch of AND.

Explain It Like I'm Five

AND means you need every rule to say yes. To get a gold star you must finish homework AND clean your room. If homework is done but the room is messy, no gold star. Both must be yes. OR would mean homework or room—either one could get a star. AND is stricter—it waits until everything passes before the IF block runs.

Exercises

  1. Write IF AGE GE 18 AND AGE LE 65 for working-age selection.
  2. Rewrite IF A OR B AND C with explicit parentheses for two different intents.
  3. Convert nested double IF into single IF with AND.
  4. Design four-condition AND for fraud hold—status, amount, region, flag.
  5. List test cases for two-condition AND truth table.

Quiz

Test Your Knowledge

1. IF AGE GE 18 AND AGE LE 65 is true when:

  • Both age tests pass
  • Either age test passes
  • Age equals 18 only
  • Never in batch jobs

2. IF STATUS EQ ACTIVE AND BALANCE GT 0 selects:

  • Active accounts with positive balance
  • All active accounts
  • All positive balances
  • Inactive accounts

3. AND has _____ precedence than OR in standard boolean logic:

  • Higher (binds tighter)
  • Lower
  • Same—order undefined
  • Neither applies in Easytrieve

4. IF NOT AMT LT 100 AND NOT AMT GT 500 means:

  • AMT between 100 and 500 inclusive
  • AMT outside range
  • Always false
  • Assignment error

5. Three conditions joined with AND require:

  • All three true
  • Any one true
  • Exactly two true
  • Compile-time constant
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 AND logical conjunction in conditional expressionsSources: Broadcom Easytrieve Report Generator 11.6 Language Reference logical operatorsApplies to: Easytrieve AND operator in IF and WHILE conditions