Easytrieve NOT Operator

NOT inverts a condition so the IF branch runs when the test would otherwise fail. IF NOT STATUS EQ CLOSED processes open accounts. IF NOT REGION EQ TEST excludes test region records from production reports. IF NOT BALANCE LT 0 selects non-negative balances—often clearer as IF BALANCE GE 0. NOT combines with AND and OR for exclusion lists: IF NOT (CODE EQ 99 OR CODE EQ 98) drops two sentinel codes. Scope matters—NOT applies to the next condition or parenthesized group, not the entire line by default. Double negatives confuse readers and auditors. De Morgan laws help rewrite NOT groups into AND and OR forms reviewers prefer. Beginners negate the wrong subexpression when mixing NOT with OR. This page teaches NOT syntax, readable alternatives with NE and GE, grouped negation, De Morgan transformations, interaction with AND and OR precedence, exclusion versus inclusion patterns, and testing inverted logic in Easytrieve batch jobs.

Progress0 of 0 lessons

NOT in Conditional Expressions

NOT precedes a relational test or parenthesized boolean expression in IF, ELSE-IF, DO WHILE, and WHILE. IF NOT ERROR-FLAG EQ YES continues processing when flag is not yes. IF NOT TRAN-DATE LT CUTOFF includes on-or-after cutoff when paired with date comparison—again GE may read clearer.

text
1
2
3
4
5
6
7
8
JOB INPUT CUSTOMER IF NOT STATUS EQ 'C' PRINT OPEN-ACCOUNT-RPT END-IF IF NOT (REGION EQ 'TST' OR REGION EQ 'DEV') PRINT PRODUCTION-RPT END-IF

NOT Truth Behavior

Single condition inversion
Original conditionResultNOT result
TrueCondition passesFalse—IF skipped
FalseCondition failsTrue—IF runs

NOT Versus Opposite Relational Operators

Many NOT forms have direct synonyms. IF NOT AMT LT 100 equals IF AMT GE 100 for numeric fields. IF NOT STATUS EQ CLOSED equals IF STATUS NE CLOSED. Prefer NE GE GT LE when they express intent in one token—listings scan faster in triage. Reserve NOT for grouped expressions: IF NOT (A AND B) or exclusion OR lists.

De Morgan Patterns

NOT (A OR B) rewrites to (NOT A) AND (NOT B). NOT (A AND B) rewrites to (NOT A) OR (NOT B). IF NOT (STATUS EQ CLOSED OR STATUS EQ DELETED) equals IF STATUS NE CLOSED AND STATUS NE DELETED for two-value tests. Choose the form your team finds readable—consistency beats cleverness across a million-line estate.

text
1
2
3
4
5
6
7
8
9
* Exclusion with grouped NOT IF NOT (DEPT EQ 999 OR DEPT EQ 998) PRINT VALID-DEPT-RPT END-IF * Equivalent AND form IF DEPT NE 999 AND DEPT NE 998 PRINT VALID-DEPT-RPT END-IF

NOT With AND

IF NOT A AND B negates only A unless grouped. IF NOT (A AND B) negates the conjunction. IF A AND NOT B requires A true and B false. Parentheses document which subexpression inverts. Mixed forms without parentheses invite misinterpretation during peer review.

NOT With OR

IF NOT A OR B passes when A is false or B is true—wide net. IF NOT (A OR B) passes only when both A and B are false—narrow exclusion. Business rule exclude codes 99 and 98 needs grouped NOT with OR inside parentheses, not NOT on first code only.

Exclusion and Allow-List Patterns

Allow-list: IF STATUS EQ A OR STATUS EQ B—positive OR. Block-list: IF NOT (STATUS EQ X OR STATUS EQ Y)—negated OR group. Single exclusion: IF NOT TYPE EQ HEADER skips header records. Sentinel filtering: IF NOT KEY EQ HIGH-VALUES when HIGH-VALUES marks end-of-file in some patterns—verify against file layout.

Double Negatives and Readability

IF NOT NOT AMT LT 0 cancels to AMT LT 0—delete redundant NOT. IF NOT (NOT ACTIVE) for active records—write IF ACTIVE EQ YES instead. Code review standards often ban double negative IF lines. Refactor during maintenance when touching legacy NOT chains.

NOT in DO WHILE and Loops

DO WHILE NOT EOF processes until end flag. WHILE NOT DONE iterates until completion sentinel. Same scope rules apply—NOT binds to following condition. Loop exit logic with NOT complements positive EOF tests on file reads.

Testing NOT Logic

  1. Verify records passing original condition fail NOT form.
  2. Verify records failing original condition pass NOT form.
  3. Compare grouped NOT OR against equivalent NE AND chain counts.
  4. Test boundary values on negated LT and LE forms.
  5. Confirm parentheses scope with mixed AND OR NOT.

Common NOT Mistakes

  • Wrong NOT scope with OR—negates only first condition.
  • Double negatives obscuring intent.
  • Using NOT LT instead of GE when GE reads clearer.
  • Assuming NOT distributes over AND without parentheses.
  • Excluding wrong sentinel values in block-list.
  • Mixing NOT with NE redundantly on same field.

Explain It Like I'm Five

NOT flips yes and no. If the rule is everyone except kids wearing red hats, you check the hat color and skip red hats—that is like NOT red hat. The IF block runs for everyone who did not match the part NOT cares about. Grouping with parentheses is like saying not (red hat or blue hat)—both colors skip. Without parentheses the sentence can mean something different, so parentheses show which part gets flipped.

Exercises

  1. Rewrite IF NOT AMT LT 100 as IF AMT GE 100.
  2. Write exclusion IF NOT (CODE EQ 99 OR CODE EQ 98) with equivalent AND form.
  3. Identify NOT scope error in IF NOT A OR B and fix with parentheses.
  4. Remove double negative from IF NOT NOT STATUS EQ ACTIVE.
  5. List test records for IF NOT DEPT EQ 10.

Quiz

Test Your Knowledge

1. IF NOT STATUS EQ CLOSED selects:

  • Records where status is not closed
  • Closed records only
  • All records unconditionally
  • Compile error always

2. IF NOT AMT LT 100 is equivalent to:

  • AMT at least 100
  • AMT below 100
  • Assign 100
  • Always false

3. NOT (A OR B) equals:

  • (NOT A) AND (NOT B)
  • (NOT A) OR (NOT B)
  • A AND B
  • Always true

4. IF NOT DEPT EQ 99 OR DEPT EQ 100 without parentheses:

  • May parse NOT only on first test—use parentheses
  • Invalid syntax
  • Same as NOT (DEPT EQ 99 OR DEPT EQ 100)
  • Assignment only

5. Double negative IF NOT NOT AMT LT 0:

  • Same as AMT LT 0
  • Same as AMT GE 0
  • Compile error
  • Always false
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 NOT logical negation in conditional expressionsSources: Broadcom Easytrieve Report Generator 11.6 Language Reference logical operatorsApplies to: Easytrieve NOT operator in IF and WHILE conditions