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.
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.
12345678JOB 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
| Original condition | Result | NOT result |
|---|---|---|
| True | Condition passes | False—IF skipped |
| False | Condition fails | True—IF runs |
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.
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.
123456789* 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
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.
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.
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.
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.
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.
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.
1. IF NOT STATUS EQ CLOSED selects:
2. IF NOT AMT LT 100 is equivalent to:
3. NOT (A OR B) equals:
4. IF NOT DEPT EQ 99 OR DEPT EQ 100 without parentheses:
5. Double negative IF NOT NOT AMT LT 0: