Logical expressions combine yes-or-no questions into one decision. Is status active and gross over the limit? Is department ten or twenty and employee type salaried? Should the input loop continue while not end of file? Easytrieve answers by evaluating conditions connected with AND, OR, and NOT inside IF, ELSE, END-IF, DO WHILE, and END-DO statements. There is no stored boolean variable type—logical expressions exist only at the moment of branch evaluation unless you copy the outcome into a one-byte flag field for later use. Beginners from languages with true and false keywords must adapt: the expression is the whole IF line condition, not a value you print. AND requires all parts true. OR requires at least one part true. NOT inverts supported conditions like NOT EOF. Precedence binds AND before OR unless parentheses say otherwise—a classic source of payroll logic bugs when OR ranges are mixed with AND guards. This page teaches connectors, condition types you can combine, evaluation order, negation, readable grouping, and patterns that replace unreadable ten-condition lines.
| Connector | Meaning | Example |
|---|---|---|
| AND | All connected conditions must be true | IF A GT 0 AND B LT 100 |
| OR | At least one condition must be true | IF DEPT EQ 10 OR DEPT EQ 20 |
| NOT | Negates following condition when supported | IF NOT EOF |
Logical connectors join conditions—not arbitrary expressions. Valid building blocks include relational comparisons (FIELD EQ value, FIELD GT value), series range conditions (FIELD EQ low THRU high), class conditions (FIELD NUMERIC, FIELD ZERO), and special constants (EOF, DUPLICATE) in input contexts. Each building block evaluates to true or false before AND OR combines them. IF GROSS GT 1000 AND STATUS EQ A AND EMPL-NUM NUMERIC stacks three condition types in one logical expression.
123IF STATUS EQ 'A' AND GROSS GT LIMIT IF SERVICE EQ 1 THRU 5 OR SERVICE EQ 99 IF ACCT NUMERIC AND BALANCE GT 0
AND means every connected condition in its group must pass. Payroll example: pay bonus only when status is active and gross exceeds threshold and department is not excluded. IF STATUS EQ A AND GROSS GT 5000 AND DEPT NE 999. One failing condition blocks the entire IF block. AND is appropriate for mandatory guards—numeric validation AND business rule AND authorization flag—all must be true before performing PUT or DISPLAY of sensitive data.
12345IF GROSS NUMERIC AND DEDUCT NUMERIC AND GROSS GT DEDUCT NET = GROSS - DEDUCT ELSE DISPLAY 'INVALID DEDUCTION' EMPL-NUM END-IF
OR means at least one connected condition must pass. Route record to exception processing when status is error or hold or gross is negative: IF STATUS EQ E OR STATUS EQ H OR GROSS LT 0. OR suits alternative valid values—department ten or twenty qualifies for union rule—IF DEPT EQ 10 OR DEPT EQ 20. Beware combining OR with AND without parentheses: IF A GT 0 AND B GT 0 OR C GT 0 may not mean what English prose suggests. See precedence section below.
123IF DEPT EQ 100 OR DEPT EQ 200 OR DEPT EQ 300 PERFORM CORP-RULES END-IF
NOT negates a condition in supported forms. Input loops commonly use DO WHILE NOT EOF to process until end of file. NOT may apply to constants and conditions per language reference for your release—not every comparison accepts NOT in all positions. When NOT readability suffers, flip the comparison: instead of NOT STATUS EQ A, use STATUS NE A if equivalent for alphabetic field.
123DO WHILE NOT EOF PERFORM PROCESS-RECORD END-DO
Without parentheses, AND groups bind tighter than OR. Expression IF A GT 0 AND B GT 0 OR C GT 0 parses as (A GT 0 AND B GT 0) OR (C GT 0)—not as A GT 0 AND (B GT 0 OR C GT 0). Misunderstanding causes production bugs when OR alternatives should apply only to one AND guard. Use explicit parentheses whenever mixing connectors in maintenance-sensitive code. Dedicated order of evaluation and parentheses pages expand precedence tables with arithmetic mixed in.
1234* Intended: A positive and (B or C positive) IF A GT 0 AND (B GT 0 OR C GT 0) PERFORM ADJUST END-IF
Parentheses wrap subexpressions to override default precedence and to document intent for auditors. IF (STATUS EQ A OR STATUS EQ P) AND GROSS GT 0 requires active or pending status and positive gross. Nested parentheses are allowed within readability limits. Over ten nested levels signal refactor time—use PROC or flag fields set in prior lines.
DO WHILE re-evaluates the logical expression each iteration. DO WHILE NOT EOF continues until EOF condition true. DO WHILE WS-COUNT LT 100 AND NOT DONE processes until count reaches hundred or DONE flag set. Ensure loop body eventually makes condition false— infinite loops from missing increment or EOF advancement still happen to beginners.
12345WS-COUNT = 0 DO WHILE WS-COUNT LT 10 AND STATUS NE 'X' PERFORM PROCESS-SLICE WS-COUNT = WS-COUNT + 1 END-DO
Class conditions—NUMERIC, ALPHABETIC, ZERO, POSITIVE, NEGATIVE—are atomic conditions in logical expressions. IF FIELD NUMERIC AND FIELD GT 0 validates before using field in later arithmetic inside the IF block. Combining class test with relational test is defensive pattern for FILE extract processing.
Range condition SERVICE EQ 6 THRU 10 is one condition true when SERVICE between six and ten inclusive. Combine with AND: IF SERVICE EQ 6 THRU 10 AND STATUS EQ A. Combine ranges with OR for multiple bands: IF CODE EQ 1 THRU 5 OR CODE EQ 90 THRU 99. THRU is inclusive on both ends per Broadcom documentation.
When logical expression exceeds one screen line, set flag fields in prior statements. VALID-SW = Y after separate IF blocks that test each rule; final IF VALID-SW EQ Y PERFORM PAY. Easier to debug in production—DISPLAY which rule failed by setting different flag values. Logical expressions stay simple; business rules distribute across readable steps.
1234567891011VALID-SW = 'N' IF GROSS NUMERIC IF STATUS EQ 'A' IF GROSS GT LIMIT VALID-SW = 'Y' END-IF END-IF END-IF IF VALID-SW EQ 'Y' PERFORM PAY-BONUS END-IF
Comparison expression is one relational test—STATUS EQ A. Logical expression combines two or more conditions with AND OR NOT. IF STATUS EQ A is only comparison. IF STATUS EQ A AND GROSS GT 0 is logical expression containing two comparisons. Terminology helps when reading expressions overview and operator pages.
SQL null state uses indicator variables—not logical NOT on field content. IF PHONE NULL tests indicator per SQL integration rules, distinct from IF PHONE EQ SPACE on host bytes. Mixing SQL null logic with batch FILE logical expressions in one program requires clear separation of host variable tests after fetch.
Logical expressions ask combo questions. AND means every question must be yes—do you have a ticket and are you tall enough? OR means at least one yes—do you want cake or ice cream? NOT flips one question—are you NOT tired means you need to not be tired for yes. Easytrieve uses your combo answer to decide whether to run the instructions inside IF or keep looping in DO WHILE.
1. IF A GT 0 AND B GT 0 is true when:
2. IF STATUS EQ A OR STATUS EQ B uses:
3. AND binds before OR meaning:
4. NOT EOF in input loop means:
5. Logical expressions appear primarily in: