In DFSORT, INCLUDE and OMIT let you filter records with a single COND= parameter. When you need to test more than one thing—for example "keep records where department is 10 and amount is positive," or "omit records where status is A or B"—you combine conditions using the keywords AND and OR. Each condition is written as a 5-tuple: (start, length, format, operator, value). You place AND or OR between conditions inside the same COND=. This page covers the syntax in detail: how to format the parentheses, where to put commas, how to continue long lines, and how to group conditions when you mix AND and OR. After reading this and the Boolean logic page, you will be able to write complex filters without leaving control statements.
Each "condition" in COND= is a single comparison: a field in the record tested against a value. The form is (start, length, format, operator, value). Start is the starting byte position (1-based). Length is the length of the field in bytes. Format is how to interpret the bytes: CH (character), PD (packed decimal), ZD (zoned decimal), BI (binary), etc. Operator is EQ, NE, GT, GE, LT, or LE. Value is the constant to compare to—for example C'ABC' for character or a numeric constant. When you combine two such conditions, you put the keyword AND or OR between them, separated by commas: (condition1,AND,condition2) or (condition1,OR,condition2).
AND means both conditions must be true. In COND= you write the first condition (full 5-tuple), then a comma, then the keyword AND, then a comma, then the second condition. Example: keep records where bytes 1–2 equal '01' and the packed-decimal field at 20–23 is greater than zero:
1INCLUDE COND=(1,2,CH,EQ,C'01',AND,20,4,PD,GT,0)
Another example: keep only records where bytes 15–17 are 'ABC' and the 2-byte binary at 25–26 is greater than 5. Here we use a hex constant for the binary comparison:
12INCLUDE COND=(15,3,CH,EQ,C'ABC',AND, 25,2,BI,GT,X'0005')
The second condition starts on the next line. Continuation is allowed; the exact rule (e.g. comma at end of line, no leading comma on next line) depends on your DFSORT version—see your manual.
OR means at least one condition must be true. You write the first condition, then comma, OR, comma, then the second condition. To keep records where a single-byte field at position 10 is either 'A' or 'B', you test the same field twice with different values:
1INCLUDE COND=(10,1,CH,EQ,C'A',OR,10,1,CH,EQ,C'B')
To keep records where region (bytes 5–6) is 'NE' or 'NW':
1INCLUDE COND=(5,2,CH,EQ,C'NE',OR,5,2,CH,EQ,C'NW')
You can chain more than two conditions: cond1,OR,cond2,OR,cond3 keeps records where any one of the three is true.
| Operator | Meaning | Typical use |
|---|---|---|
| AND | Both conditions must be true | Narrow the set (e.g. region=North AND amount>100) |
| OR | At least one condition must be true | Widen the set (e.g. code=A OR code=B) |
Use AND when you want to narrow the set: every criterion must be met. Use OR when you want to widen the set: any one of several criteria is enough. Mixing them requires parentheses so the grouping is clear.
When you have both AND and OR in one COND=, use parentheses to group subexpressions. For example, "keep records where (dept=10 and amount>0) or (dept=20 and amount>100)". In DFSORT-style syntax you could write:
123INCLUDE COND=((10,2,CH,EQ,C'10',AND,20,4,PD,GT,0), OR, (10,2,CH,EQ,C'20',AND,20,4,PD,GT,100))
The inner parentheses group the two AND pairs; the OR connects the two groups. Parenthesis and continuation rules are product-specific—consult the DFSORT Application Programming Guide for your release.
OMIT uses the same COND= syntax. OMIT COND=(cond1,AND,cond2) omits (drops) records when both conditions are true. OMIT COND=(cond1,OR,cond2) omits records when either condition is true. Example: drop all records where byte 7 is 'X' or 'Y':
1OMIT COND=(7,1,CH,EQ,C'X',OR,7,1,CH,EQ,C'Y')
So you do not need different syntax for OMIT; only the meaning changes (omit vs include when the condition is true).
Long COND= expressions can be continued to the next line. Common practice is to break after a comma (e.g. after the first full condition or after AND/OR). The continued line usually does not start with a comma. Some systems use a specific continuation character in column 72 or elsewhere. Incorrect continuation (e.g. a leading comma on the new line) can cause syntax errors. Always verify with your installation's DFSORT documentation.
The (start,length) in each condition refer to the record as seen at the time INCLUDE/OMIT is applied. If you use INREC, that is after INREC has reformatted the record. So if INREC builds a new 50-byte record, your condition positions are 1–50 in that reformatted record, not the original input positions. If you do not use INREC, positions refer to the original input record.
AND is like a checklist: you must have a hat and a coat to go out. If you forget one, you don't go. OR is like having two doors: you can go out door A or door B; either one is fine. In DFSORT we write these as (rule1,AND,rule2) or (rule1,OR,rule2). The commas and the words AND and OR tell the sort program how to combine the rules. Parentheses are like putting a fence around a group so the program knows "do this group first, then combine it with the other group."
1. What is the correct way to write two conditions with AND in INCLUDE COND=?
2. For OR, how do you keep records where byte 10 is either A or B?
3. When continuing a long COND= to the next line, what is a common rule?
4. How do you express (field1=1 AND field2=2) OR (field3=3 AND field4=4)?
5. Can OMIT use the same AND/OR syntax as INCLUDE?