MainframeMaster

Comparison Operators in INCLUDE and OMIT

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.

INCLUDE / OMIT Advanced Filtering
Progress0 of 0 lessons

The Six Comparison Operators

DFSORT comparison operators used in COND=
OperatorNameMeaningExample meaning
EQEqualField value equals the constantStatus = 'A'
NENot equalField value does not equal the constantCode ≠ '99'
GTGreater thanField value is strictly greater than the constantAmount > 100
GEGreater than or equalField value is >= the constantAmount ≥ 0
LTLess thanField value is strictly less than the constantYear < 2000
LELess than or equalField value is <= the constantCount ≤ 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 — Equal

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 — Not Equal

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 and GE — Greater Than / Greater Than or Equal

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 and LE — Less Than / Less Than or Equal

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).

Character vs Numeric Comparison

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.

Examples in Context

Keep records where byte 7 is exactly 'A':

text
1
INCLUDE COND=(7,1,CH,EQ,C'A')

Keep records where packed-decimal amount at 20–23 is greater than or equal to 100:

text
1
INCLUDE COND=(20,4,PD,GE,100)

Omit records where bytes 1–2 are '00' (e.g. invalid code):

text
1
OMIT COND=(1,2,CH,EQ,C'00')

Keep records where binary field at 30–33 is not zero:

text
1
INCLUDE COND=(30,4,BI,NE,0)

Explain It Like I'm Five

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).

Exercises

  1. Write a condition to keep records where the zoned-decimal field at 50–53 is less than 0.
  2. What is the difference between LT and LE for the value 100? Give an example COND= for each that would keep 100.
  3. Write OMIT COND= to drop records where bytes 10–11 equal '99'.
  4. If you want to keep records where a character code (1 byte) is A, B, or C, would you use one INCLUDE with OR and three EQ conditions, or something else? Write the COND= (one INCLUDE, OR).

Quiz

Test Your Knowledge

1. Which operator means "not equal" in DFSORT COND=?

  • EQ
  • NE
  • EQN
  • NOTEQ

2. What is the difference between GT and GE?

  • No difference
  • GT = greater than; GE = greater than or equal—GE allows equality
  • GE is for character only
  • GT is for numeric only

3. For character (CH) fields, how does DFSORT compare values?

  • Alphabetically in ASCII
  • Using the collating sequence in effect (typically EBCDIC)—byte by byte
  • Case-insensitive only
  • CH does not support comparison

4. Which operator would you use to keep records where a numeric field is at least 50?

  • GT
  • GE—greater than or equal includes 50
  • LT
  • EQ

5. Do LT and LE work with both character and numeric formats?

  • No, only numeric
  • Yes—with CH they use collating order; with PD/ZD/BI they use numeric order
  • Only with CH
  • Only with BI