The INCLUDE control statement filters input records: only records that satisfy the condition you specify are kept and passed to the sort or merge phase; all others are dropped. You define the condition with INCLUDE COND= using a field position, length, format, a comparison operator, and a value. INCLUDE is applied during the input phase, before any sort or merge, so it reduces the amount of data that gets sorted. This page covers the syntax of INCLUDE COND=, the comparison operators, character and numeric examples, and how INCLUDE differs from OMIT.
INCLUDE is a filter. For each input record, DFSORT evaluates the condition you give in COND=. If the condition is true, the record is kept—it is passed to the sort or merge phase and can appear in the output. If the condition is false, the record is discarded—it is not sorted and not written. So INCLUDE is "keep only records that match." This happens during the input phase, so records that do not match never enter the sort or merge. That can save time and memory when a large fraction of the input would otherwise be dropped.
The basic form is:
1INCLUDE COND=(start,length,format,operator,value)
The record is kept if (field operator value) is true. For example, COND=(1,1,CH,EQ,C\'A\') keeps records where the first byte equals the character A.
EQ — Equal. The field must equal the value. NE — Not equal. The field must not equal the value. GT — Greater than. The field must be greater than the value. GE — Greater than or equal. LT — Less than. LE — Less than or equal. For character fields, comparison is usually in EBCDIC (or the collating sequence in effect). For numeric formats (PD, ZD, BI), the comparison is numeric. So (10,4,PD,GT,0) keeps records where the packed-decimal field in bytes 10–13 is greater than zero.
1INCLUDE COND=(1,1,CH,EQ,C'A')
Keeps only records where byte 1 is the character A. All other records are dropped.
1INCLUDE COND=(5,2,CH,EQ,C'NY')
Keeps only records where bytes 5–6 are the two characters NY (e.g. state code). Records with any other value in those positions are dropped.
1INCLUDE COND=(20,4,PD,GE,100)
Keeps records where the 4-byte packed-decimal field starting at position 20 is greater than or equal to 100. Records with a value less than 100 are dropped.
1INCLUDE COND=(30,1,BI,NE,0)
Keeps records where the 1-byte binary field at position 30 is not equal to zero. (For 1-byte binary, length 1 is typical; for fullword use length 4.)
If you use both INREC and INCLUDE, INREC is applied first. So the record layout and content that INCLUDE sees are the reformatted record (after INREC). The positions in your INCLUDE COND= refer to that reformatted record, not the original input. If you do not use INREC, positions refer to the original input record.
INCLUDE keeps records that match the condition and drops the rest. OMIT drops records that match the condition and keeps the rest. So INCLUDE COND=(1,1,CH,EQ,C\'X\') keeps only X; OMIT COND=(1,1,CH,EQ,C\'X\') keeps everything except X. Use INCLUDE when you want to keep a subset (e.g. "only records for region A"). Use OMIT when you want to exclude a subset (e.g. "drop all header records"). You can use both in the same job: a record is kept only if it passes INCLUDE (if present) and does not match OMIT (if present). Often one or the other is enough.
INCLUDE is like a gatekeeper. You tell the gatekeeper: "Only let through cards that have an A in the first spot" (or "only cards where the number in the middle is bigger than 100"). Every card is checked. If it matches, it goes through to the sorting machine. If it doesn't match, it goes in the trash. So INCLUDE is the rule that says who gets to be sorted and who doesn't.
1. What does INCLUDE do in DFSORT?
2. When is INCLUDE applied?
3. What does INCLUDE COND=(1,5,CH,EQ,C'HELLO') do?
4. Can you use both INCLUDE and OMIT in the same job?
5. Which comparison operator means "greater than or equal"?