MainframeMaster

Boolean Logic in INCLUDE and OMIT

When you filter records with INCLUDE or OMIT, you often need more than one test: for example, "keep records where region is North and amount is greater than 100," or "omit records where status is X or Y." Boolean logic is the way you combine such conditions. In DFSORT you do this inside a single COND= parameter by joining conditions with AND or OR. AND means the record must satisfy all of the listed conditions (they all must be true). OR means the record must satisfy at least one of the conditions. Understanding AND and OR—and how to group them with parentheses when you mix both—lets you build precise filters without writing a program. This page explains boolean logic in DFSORT INCLUDE and OMIT, with examples and truth tables.

INCLUDE / OMIT Advanced Filtering
Progress0 of 0 lessons

What Is Boolean Logic?

Boolean logic deals with true and false and the operators that combine them. In DFSORT, each condition in INCLUDE or OMIT evaluates to true or false for a given record (e.g. "byte 5 equals A" is either true or false). AND and OR combine these results: with AND, the combined expression is true only when every part is true; with OR, the combined expression is true when at least one part is true. So AND makes the filter stricter (fewer records pass); OR makes it looser (more records pass).

AND: All Conditions Must Be True

When you connect two or more conditions with AND, the record is kept (for INCLUDE) or omitted (for OMIT) only when all of those conditions are true. If any one condition is false, the whole expression is false. So AND is used when you want to narrow the set: "region = North AND amount > 100" keeps only records that satisfy both.

AND truth table: result is true only when both inputs are true
Condition 1 AND Condition 2Result
True AND TrueTrue
True AND FalseFalse
False AND TrueFalse
False AND FalseFalse

In DFSORT syntax you write: INCLUDE COND=(condition1,AND,condition2). Each condition is typically a 5-tuple (start,length,format,operator,value). The record is kept only if condition1 is true and condition2 is true.

OR: At Least One Condition Must Be True

When you connect conditions with OR, the record is kept or omitted if any of the conditions is true. Only when every condition is false is the whole expression false. So OR is used when you want to broaden: "status = X OR status = Y" keeps (or omits) records that match either value.

OR truth table: result is true when at least one input is true
Condition 1 OR Condition 2Result
True OR TrueTrue
True OR FalseTrue
False OR TrueTrue
False OR FalseFalse

In DFSORT you write: INCLUDE COND=(condition1,OR,condition2). The record is kept if condition1 is true or condition2 is true (or both).

Syntax: Combining Conditions in COND=

A single condition has the form (start,length,format,operator,value). To combine two conditions with AND you list the first condition, then the keyword AND, then the second condition. Same for OR. Continuation lines are allowed; follow your product's rules (e.g. no leading comma on the next line). Example with AND:

text
1
2
INCLUDE COND=(15,3,CH,EQ,C'ABC',AND, 25,2,BI,GT,X'0005')

This keeps only records where bytes 15–17 equal the character constant 'ABC' and the 2-byte binary field at positions 25–26 is greater than 5. Both must be true.

Example with OR:

text
1
INCLUDE COND=(10,1,CH,EQ,C'A',OR,10,1,CH,EQ,C'B')

This keeps records where the character in position 10 is 'A' or 'B'. Either one is enough.

Mixing AND and OR: Use Parentheses

When you have both AND and OR in the same COND=, the order of evaluation matters. For example, "A and B or C and D" can mean (A and B) or (C and D), or it can mean A and (B or C) and D. In DFSORT you use parentheses to group subexpressions. Typical form: INCLUDE COND=((cond1,AND,cond2),OR,(cond3,AND,cond4)). The outer parentheses belong to COND=; the inner ones define groups. So (cond1 AND cond2) is one group, (cond3 AND cond4) is another, and the two groups are combined with OR. Check your DFSORT Application Programming Guide for the exact parenthesis and continuation rules for your release.

Boolean Logic and OMIT

OMIT uses the same COND= syntax. The only difference is the action: when the combined condition is true, the record is omitted (dropped). So OMIT COND=(cond1,OR,cond2) drops a record if cond1 is true or cond2 is true. OMIT COND=(cond1,AND,cond2) drops a record only when both are true. The boolean logic is identical; INCLUDE keeps when true, OMIT drops when true.

One INCLUDE or OMIT Statement

In DFSORT you normally have one INCLUDE statement or one OMIT statement in a job. All of your criteria are expressed inside that single COND= by combining conditions with AND and OR. So instead of "first INCLUDE for A, second INCLUDE for B," you write one INCLUDE with (A,AND,B) or (A,OR,B) as needed. This keeps the filter definition in one place and avoids ambiguity about how multiple statements interact.

Explain It Like I'm Five

Imagine a bouncer at a party. AND is like saying "you must have a ticket and be wearing green." If you have a ticket but no green, you don't get in. Both rules must be satisfied. OR is like "you get in if you have a ticket or you know the host." Either one is enough. In DFSORT, INCLUDE is the bouncer letting in only the records that pass the rules; OMIT is the bouncer kicking out the records that pass the rules. AND and OR are just the way we write those rules.

Exercises

  1. Write an INCLUDE that keeps records where bytes 1–2 equal '01' and bytes 20–23 (packed decimal) are greater than 0.
  2. Write an OMIT that drops records where byte 5 is 'X' or byte 5 is 'Y'.
  3. What is the difference between INCLUDE COND=(A,AND,B) and INCLUDE COND=(A,OR,B) in terms of how many records pass?
  4. If you want to keep records where (region=North and amount>100) or (region=South and amount>200), how would you group the conditions in COND=?

Quiz

Test Your Knowledge

1. In DFSORT, what does AND mean when combining two conditions in INCLUDE COND=?

  • Keep the record if either condition is true
  • Keep the record only if both conditions are true
  • Keep the first condition only
  • AND is not supported

2. What does OR mean in INCLUDE COND=?

  • Keep the record only if both conditions are true
  • Keep the record if at least one condition is true
  • Keep only the first matching condition
  • OR reverses the condition

3. Can you use both AND and OR in the same INCLUDE COND=?

  • No
  • Yes—use parentheses to group subexpressions so AND/OR apply in the order you want
  • Only in OMIT
  • Only two conditions allowed

4. How does boolean logic apply to OMIT?

  • OMIT does not support AND/OR
  • Same as INCLUDE: the condition is evaluated; if true the record is omitted
  • OMIT uses NOT instead of AND/OR
  • OMIT keeps records where the condition is true

5. Why would you use AND instead of multiple INCLUDE statements?

  • You cannot use multiple INCLUDE statements
  • One INCLUDE with AND keeps records that meet all criteria at once; multiple INCLUDEs may not be supported or may behave as OR
  • AND is faster
  • Multiple INCLUDEs are the same as AND