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.
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.
12345678JOB 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
| Condition A | Condition B | A AND B |
|---|---|---|
| True | True | True—IF branch runs |
| True | False | False—IF branch skipped |
| False | True | False—IF branch skipped |
| False | False | False—IF branch skipped |
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.
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.
12345678JOB 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
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.
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.
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 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.
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.
1. IF AGE GE 18 AND AGE LE 65 is true when:
2. IF STATUS EQ ACTIVE AND BALANCE GT 0 selects:
3. AND has _____ precedence than OR in standard boolean logic:
4. IF NOT AMT LT 100 AND NOT AMT GT 500 means:
5. Three conditions joined with AND require: