MainframeMaster

INCLUDE Statement

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.

Control Statements
Progress0 of 0 lessons

What INCLUDE Does

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.

INCLUDE COND= Syntax

The basic form is:

text
1
INCLUDE COND=(start,length,format,operator,value)
  • start — Starting byte position of the field to test (1-based).
  • length — Length of the field in bytes.
  • format — How to interpret the field: CH (character), PD (packed decimal), ZD (zoned decimal), BI (binary), etc. Must match the data so the comparison is correct.
  • operator — Comparison: EQ (equal), NE (not equal), GT (greater than), GE (greater than or equal), LT (less than), LE (less than or equal).
  • value — The value to compare against. For character: C\'...\' (e.g. C\'A\' or C\'HELLO\'). For numeric: the constant in the appropriate form (e.g. 100 for a numeric test).

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.

Comparison Operators

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.

Character Examples

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

Keeps only records where byte 1 is the character A. All other records are dropped.

text
1
INCLUDE 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.

Numeric Examples

text
1
INCLUDE 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.

text
1
INCLUDE 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.)

Order of Operations: INREC Then INCLUDE

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 vs OMIT

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.

Explain It Like I'm Five

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.

Exercises

  1. Write an INCLUDE that keeps only records where bytes 10–11 are the characters '01'.
  2. Write an INCLUDE that keeps only records where the packed-decimal field at positions 40–43 is greater than 0.
  3. If you use INREC to build a 50-byte record, and you want to filter by a field that is now at positions 1–3 in that record, what do you put in INCLUDE COND=?
  4. What is the difference between INCLUDE and OMIT for the same condition?

Quiz

Test Your Knowledge

1. What does INCLUDE do in DFSORT?

  • Includes the first n records only
  • Keeps only records that satisfy the COND= condition; all others are dropped
  • Includes SYSIN in the output
  • Includes SORTIN in SORTOUT

2. When is INCLUDE applied?

  • After the sort phase
  • During the output phase
  • During the input phase, before sort/merge
  • Only when OPTION COPY is used

3. What does INCLUDE COND=(1,5,CH,EQ,C'HELLO') do?

  • Sorts by bytes 1-5
  • Keeps only records where bytes 1-5 equal the character constant HELLO
  • Omits records with HELLO
  • Copies bytes 1-5 to output

4. Can you use both INCLUDE and OMIT in the same job?

  • No, never
  • Yes, but only one will effectively apply to a given record
  • Only for MERGE
  • Only with OPTION COPY

5. Which comparison operator means "greater than or equal"?

  • GT
  • GE
  • EQ
  • NE