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.
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).
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.
| Condition 1 AND Condition 2 | Result |
|---|---|
| True AND True | True |
| True AND False | False |
| False AND True | False |
| False AND False | False |
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.
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.
| Condition 1 OR Condition 2 | Result |
|---|---|
| True OR True | True |
| True OR False | True |
| False OR True | True |
| False OR False | False |
In DFSORT you write: INCLUDE COND=(condition1,OR,condition2). The record is kept if condition1 is true or condition2 is true (or both).
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:
12INCLUDE 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:
1INCLUDE 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.
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.
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.
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.
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.
1. In DFSORT, what does AND mean when combining two conditions in INCLUDE COND=?
2. What does OR mean in INCLUDE COND=?
3. Can you use both AND and OR in the same INCLUDE COND=?
4. How does boolean logic apply to OMIT?
5. Why would you use AND instead of multiple INCLUDE statements?