Blog enJCL

INCLUDE Condition – SORT in JCL

In JCL (Job Control Language), the INCLUDE condition is used in the context of the SORT step to specify a set of records that should be included in the output of the sorting step. The INCLUDE clause helps filter records based on specific criteria, retaining only those that meet the condition. Here’s a basic layout and explanation of the INCLUDE condition’s features:

Within the INCLUDE condition in JCL, you can specify different types of fields and use various comparison operators. Below are some common field types and operators you can use:

Field Types

Characters (CH)
CH: Character fields, used to compare text strings. Without COMP.
INCLUDE COND=(1,10,CH,EQ,C'MAINFRAME')

Hexadecimal (BI)
BI: Hexadecimal fields, used to compare hexadecimal character strings, with COMP.
For hexadecimal constants, remember padding and truncation rules. If you specify X’0A’, the string is padded to the right rather than to the left. For decimal constants, you can use 10 or +10, with no need to worry about padding or truncation.
INCLUDE COND=(1,4,BI,EQ,X'0000000A')

Numeric (PD)
PD: Numeric fields, used to compare numeric values.
INCLUDE COND=(11,5,PD,GT,1000)

Date (YMD, DMY, MDY, etc.)
You can specify a date format for date fields.
INCLUDE COND=(21,8,YMD,EQ,C'20220119')

Comparison Operators

Equal (EQ)
EQ: Equal.
INCLUDE COND=(1,5,CH,EQ,C'ABC')

Not Equal (NE)
NE: Not equal.
INCLUDE COND=(6,3,PD,NE,500)

Greater Than (GT), Less Than (LT)
GT: Greater than.
LT: Less than.
INCLUDE COND=(11,5,PD,GT,1000)

Greater Than or Equal To (GE), Less Than or Equal To (LE)
GE: Greater than or equal to.
LE: Less than or equal to.
INCLUDE COND=(21,8,YMD,GE,C'20220119')

Between (BE)
BE: Between. Used to specify a range.
INCLUDE COND=(31,3,PD,BE,100,500)

LIKE
LIKE: Used for pattern-based comparisons (similar to regular expressions).
INCLUDE COND=(1,10,CH,LIKE,C'MAIN%')

AND, OR, NOT

  • AND: Logical “AND” operator.
  • OR: Logical “OR” operator.
  • NOT: Logical negation operator.
    INCLUDE COND=((1,5,CH,EQ,C'ABC'),AND,(6,3,PD,GT,500))

These are just a few examples of the field types and comparison operators you can use within the INCLUDE condition in JCL. The specific documentation for the sort product you are using will provide more precise details and additional options.

Example JCL with INCLUDE

//SORTJOB  JOB  (123),'Sort with INCLUDE',CLASS=A,MSGCLASS=X,MSGLEVEL=(1,1)
//STEP1    EXEC PGM=SORT
//SYSOUT   DD  SYSOUT=A
//SORTIN   DD  DSN=your.input.file,DISP=SHR
//SORTOUT  DD  DSN=your.output.file,DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,SPACE=(CYL,(5,5),RLSE)
//SYSIN    DD  *
  SORT FIELDS=(1,10,A)
  INCLUDE COND=(11,2,CH,EQ,C'20')
/*

In this example, the INCLUDE condition is used to include only the records that meet the specified condition. In this case, records where the content in positions 11 and 12 is equal to ’20’. The structure of the condition is as follows:

  • COND=(position, length, type, operator, value):
  • position: Start position of the field.
  • length: Field length.
  • type: Field type (e.g., CH for characters).
  • operator: Comparison operator (e.g., EQ for equal).
  • value: Value to compare against the field.

Features of the INCLUDE Condition:

  1. Versatility:
  • You can specify complex conditions using logical operators (AND, OR, NOT) to combine multiple conditions.
  1. Field Types:
  • You can apply conditions to various field types, such as character fields (CH), numeric fields (PD), and date fields (YMD, DMY, etc.).
  1. Comparison Operators:
  • Various comparison operators are available, such as equal (EQ), not equal (NE), greater than (GT), less than (LT), greater than or equal to (GE), less than or equal to (LE), among others.
  1. Negation:
  • You can negate a condition using NOT to select records that do not meet the condition.
  1. Condition Combination:
  • You can combine multiple conditions using logical operators to create more complex criteria.

Example of a Combined Condition:

INCLUDE COND=((11,2,CH,EQ,C'20'),AND,(21,3,PD,GT,100))

In this example, records that meet both conditions will be included: those with the first two characters equal to ’20’ and the following three characters as a number greater than 100.

Leave a Reply

Your email address will not be published. Required fields are marked *