Easytrieve Logical Expressions

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.

Progress0 of 0 lessons

Logical Connectors

AND OR NOT behavior
ConnectorMeaningExample
ANDAll connected conditions must be trueIF A GT 0 AND B LT 100
ORAt least one condition must be trueIF DEPT EQ 10 OR DEPT EQ 20
NOTNegates following condition when supportedIF NOT EOF

Conditions You Can Connect

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.

text
1
2
3
IF 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 Expressions

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.

text
1
2
3
4
5
IF GROSS NUMERIC AND DEDUCT NUMERIC AND GROSS GT DEDUCT NET = GROSS - DEDUCT ELSE DISPLAY 'INVALID DEDUCTION' EMPL-NUM END-IF

OR Expressions

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.

text
1
2
3
IF DEPT EQ 100 OR DEPT EQ 200 OR DEPT EQ 300 PERFORM CORP-RULES END-IF

NOT Expressions

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.

text
1
2
3
DO WHILE NOT EOF PERFORM PROCESS-RECORD END-DO

Precedence: AND Before OR

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.

text
1
2
3
4
* 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 for Grouping

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.

Logical Expressions in DO WHILE

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.

text
1
2
3
4
5
WS-COUNT = 0 DO WHILE WS-COUNT LT 10 AND STATUS NE 'X' PERFORM PROCESS-SLICE WS-COUNT = WS-COUNT + 1 END-DO

Class Conditions in Logical Expressions

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.

Series THRU in Logical Context

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.

Replacing Complex Logic with Flags

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.

text
1
2
3
4
5
6
7
8
9
10
11
VALID-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

Logical vs Comparison Expressions

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 and NULL in Logical Tests

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.

Common Logical Expression Mistakes

  • AND OR precedence without parentheses—wrong branch taken.
  • IF A AND B without relational operators on numeric fields.
  • Using = instead of EQ inside conditions.
  • Ten-condition line unmaintainable—refactor to flags.
  • DO WHILE never false—infinite loop.
  • NOT placement ambiguous—rewrite as NE or explicit parentheses.

Explain It Like I'm Five

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.

Exercises

  1. Write IF with AND requiring status active and gross over limit.
  2. Write IF with OR for three valid department codes.
  3. Add parentheses to change meaning of A AND B OR C.
  4. Convert complex AND chain to VALID-SW flag pattern.
  5. Write DO WHILE NOT EOF with body incrementing counter.

Quiz

Test Your Knowledge

1. IF A GT 0 AND B GT 0 is true when:

  • Both A GT 0 and B GT 0 are true
  • Either condition is true
  • Never
  • Compile time only

2. IF STATUS EQ A OR STATUS EQ B uses:

  • Logical OR between two comparisons
  • Arithmetic add
  • FILE concat
  • Exponentiation

3. AND binds before OR meaning:

  • AND groups evaluate before OR unless parentheses override
  • OR always first
  • Random order
  • Compile error

4. NOT EOF in input loop means:

  • Continue while end of file not reached
  • Stop immediately
  • Skip file
  • Compile only

5. Logical expressions appear primarily in:

  • IF DO WHILE and similar conditional statements
  • FILE statement
  • DD only
  • TITLE only
Published
Read time16 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 AND OR NOT condition combination in IF statementsSources: Broadcom Easytrieve 11.6 Language Reference conditional expressions, Getting Started IF examplesApplies to: Easytrieve logical expressions