INCLUDE Statement
INCLUDE Statement
The INCLUDE control statement is used to select specific records from a file that meet certain conditions. It allows us to filter records by defining criteria such as values in particular fields, and only those records that satisfy the conditions are processed. All other records are excluded from the operation.
Syntax1 - Comparing with a constant
//SYSIN DD *
SORT FIELDS=COPY
INCLUDE COND=(field1_starting_position, field1_length, field1_format,
relational_operator, constant)
/*
Syntax2 - Comparing with another field
//SYSIN DD *
SORT FIELDS=COPY
INCLUDE COND=(field1_starting_position, field1_length, field1_format,
relational_operator, field2_starting_position, field2_length, field2_format)
/*
field1_starting_position | Specifies the starting position of field1 to be compared |
field1_length | Specifies the length of the field1 to be compared |
field1_format | Specifies the format of the field1. Format types include: CH (Character), ZD (Zoned Decimal), PD (Packed Decimal) and BI (Binary). |
relational_operator | used for condition comparison. The available operators are -
EQ Equal to NE Not equal to GT Greater than GE Greater than or equal to LT Less than LE Less than or equal to |
field2_starting_position | Specifies the starting position of field2 to be compared |
field2_length | Specifies the length of the field2 to be compared |
field2_format | Specifies the format of the field2. |
Examples -
Scenario1 - Simple Character Comparison.
INCLUDE COND=(1,5,CH,EQ,C'HELLO')
Scenario2 - Numeric Comparison Using Zoned Decimal (ZD).
INCLUDE COND=(10,4,ZD,GT,1000)
Scenario3 - Multiple Conditions Using AND
INCLUDE COND=(1,3,CH,EQ,C'ABC',AND,10,5,ZD,LE,500)
Scenario4 - Multiple Conditions Using OR
INCLUDE COND=(1,3,CH,EQ,C'XYZ',OR,5,4,CH,EQ,C'ABCD')