INCLUDE Coding Constants


Coding constants within the INCLUDE statement refers to using fixed values (constants) as part of a condition to filter records. Constants are used to compare against fields in the records, choosing which records should be included in the processing (sort, merge, or copy). These constants can be alphanumeric, numeric, or hexadecimal values.

Syntax -

//SYSIN DD * 
    SORT FIELDS=COPY
    INCLUDE COND=(field1_starting_position, field1_length, field1_format,
		 relational_operator, constant)
/*

There are different formats to code different constants in the condition and those are shown below -

Alphanumeric or character strings (CH)Used for alphanumeric string comparisons. The format is: C'a...z' where x is a character.
Hexadecimal strings Used for hexadecimal comparisons. The format is: X'yy...yy' where yy is a pair of hexadecimal digits.
Numeric values or Numbers (ZD, PD, BI)Used for numeric comparisons. The format is: n...n or ±n...n where n is a decimal digit.
field1_starting_positionSpecifies the starting position of field1 to be compared
field1_lengthSpecifies the length of the field1 to be compared
field1_formatSpecifies the format of the field1. Use BI (Binary) for Alphanumeric tests
relational_operatorused 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
ConstantSpecifies the constant to be compared

Examples -


Scenario1 - Alphanumeric Constant.

INCLUDE COND=(1,3,CH,EQ,C'ABC')

It includes only records where the first 3 characters of the record are equal to 'ABC'.

Scenario2 - Numeric Constant (Zoned Decimal).

INCLUDE COND=(10,5,ZD,GT,5000)

It includes records where the 5-byte zoned decimal field starting at position 10 is greater than 5000.

Scenario3 - Packed Decimal Constant

INCLUDE COND=(15,4,PD,EQ,100)

It includes records where the 4-byte packed decimal field starting at position 15 equals 100.

Scenario4 - Multiple Conditions with Constants (AND).

INCLUDE COND=(1,3,CH,EQ,C'XYZ',AND,20,4,ZD,GE,1000)

It includes records where the first 3 characters (starting at position 1) are equal to 'XYZ' and the 4-byte zoned decimal field starting at position 20 is greater than or equal to 1000.

Scenario5 - Multiple Conditions with Constants (OR).

INCLUDE COND=(5,2,CH,EQ,C'AA',OR,10,3,CH,EQ,C'123')

It includes records where the 2-character field starting at position 5 equals 'AA', or the 3-character field starting at position 10 equals '123'.