When you write an INCLUDE or OMIT condition in DFSORT, you compare a field in the record to a value. The comparison operator defines how that comparison is done: equal, not equal, greater than, and so on. DFSORT provides six operators: EQ (equal), NE (not equal), GT (greater than), GE (greater than or equal), LT (less than), and LE (less than or equal). You code them in the COND=(start, length, format, operator, value) parameter. The operator goes in the fourth position. For character (CH) fields, comparison follows the collating sequence (typically EBCDIC). For numeric formats (PD, ZD, BI, etc.), comparison is by numeric value. Choosing the right operator—and the right format so the comparison is meaningful—is essential for correct filtering. This page explains each operator, how it behaves with character vs numeric data, and gives examples.
| Operator | Name | Meaning | Example meaning |
|---|---|---|---|
| EQ | Equal | Field value equals the constant | Status = 'A' |
| NE | Not equal | Field value does not equal the constant | Code ≠ '99' |
| GT | Greater than | Field value is strictly greater than the constant | Amount > 100 |
| GE | Greater than or equal | Field value is >= the constant | Amount ≥ 0 |
| LT | Less than | Field value is strictly less than the constant | Year < 2000 |
| LE | Less than or equal | Field value is <= the constant | Count ≤ 10 |
In COND= you always specify the operator as the fourth element: (start, length, format, operator, value). The condition is true when (field operator value) is true. For example, (10,4,PD,GT,0) is true when the 4-byte packed-decimal field at position 10 is greater than zero.
EQ means the field value must equal the constant exactly. For character fields, length must match: if the field is 5 bytes, the constant should be 5 bytes (e.g. C'HELLO'). For numeric fields, the comparison is by value. Example: INCLUDE COND=(1,1,CH,EQ,C'A') keeps only records where the first byte is the character A. INCLUDE COND=(20,4,PD,EQ,100) keeps records where the packed-decimal field at 20–23 equals 100.
NE means the field value must not equal the constant. So the condition is true when the field is different from the value. Use NE when you want to exclude one (or a few) values and keep everything else—often with OMIT you would use EQ to drop a specific value, but with INCLUDE you might use NE to keep all except one. Example: OMIT COND=(5,2,CH,EQ,C'99') drops records where bytes 5–6 are '99'; equivalently, INCLUDE COND=(5,2,CH,NE,C'99') keeps all records where bytes 5–6 are not '99'.
GT means strictly greater than: the field must be greater than the value; if they are equal, the condition is false. GE means greater than or equal: the condition is true when the field is greater than the value or equal to it. So GE is "at least" the value; GT is "more than" the value. For numeric fields: (30,4,PD,GT,0) keeps positive values only (excludes zero); (30,4,PD,GE,0) keeps zero and all positive values. For character fields, GT/GE use the collating sequence—so (1,3,CH,GT,C'AAA') is true for 3-byte character strings that collate after 'AAA'.
LT means strictly less than; LE means less than or equal. So LE is true when the field is less than the value or equal to it; LT is false when they are equal. Example: to keep records where a date field (e.g. YYYYMMDD in positions 1–8) is on or before 20231231, use COND=(1,8,CH,LE,C'20231231') if the date is stored as character. For a numeric amount that must be at most 1000: (40,4,PD,LE,1000).
For CH (character) fields, DFSORT compares using the collating sequence in effect—usually EBCDIC. Comparison is byte-by-byte from left to right. So the order of two character strings depends on the code page and any ALTSEQ table. For PD, ZD, BI, and other numeric formats, the field is interpreted as a number and compared by numeric value. So (10,4,PD,GT,0) compares the numeric value of the 4-byte packed field to zero; the byte pattern is not compared as character. Always use the format that matches your data: if the field is packed decimal, use PD so the comparison is correct.
Keep records where byte 7 is exactly 'A':
1INCLUDE COND=(7,1,CH,EQ,C'A')
Keep records where packed-decimal amount at 20–23 is greater than or equal to 100:
1INCLUDE COND=(20,4,PD,GE,100)
Omit records where bytes 1–2 are '00' (e.g. invalid code):
1OMIT COND=(1,2,CH,EQ,C'00')
Keep records where binary field at 30–33 is not zero:
1INCLUDE COND=(30,4,BI,NE,0)
The operators are like signs on a gate. EQ says "only if it's exactly this." NE says "only if it's not this." GT says "only if it's bigger" and GE says "only if it's bigger or the same." LT and LE are the same for "smaller." So when the sort program looks at each record, it checks the sign: does this record pass the test? If yes, INCLUDE keeps it and OMIT drops it (or the other way around—INCLUDE keeps, OMIT drops when the condition is true).
1. Which operator means "not equal" in DFSORT COND=?
2. What is the difference between GT and GE?
3. For character (CH) fields, how does DFSORT compare values?
4. Which operator would you use to keep records where a numeric field is at least 50?
5. Do LT and LE work with both character and numeric formats?