INCLUDE Statement
INCLUDE Statement
Summary
- INCLUDE control statement is used to specify the selection criteria.
- Including records can copy the specific set of records which satisfies the condition provided. In this scenario, only selected records which satisfy the condition specified will be copied to output file.
Syntax1 - Comparing with a constant
INCLUDE COND=(Field1 starting position, Field1 Length,
Field1 format_type, Relational Operator, constant)
Syntax2 - Comparing with another field
INCLUDE COND=(field1 starting position, field1 Length,
field1 format_type, Relational Operator,
field2 starting position, field2 Length,field2 format_type)
Field1 starting position | Starting position of field1 to be compared |
Field1 Length | Length of the field1 to be compared |
Field1 format_type | Format of the field1 like CH, PD, BI etc,. |
Relation operator | Relational operators like GT, EQ, NE, LT etc,.
|
Field2 starting position | Starting position of field2 which is to be compared with Field1 |
field2 Length | Length of field2 which is to be compared with field1 |
Field2 Format_type | Format of the field2 like CH, PD, BI etc,. |
Example - Comparing with a constant
Scenario - From the below data, filter the records having the ID is 00001. ID starts from 1st and ends at 5th column in the file.
Input File - MTH.SORT.INPUT
----+----1----+----2---+----3---+----4---+---5----+---6----+----7---+----8
********************************* Top of Data ******************************
00002 Srinivas Employee
test test test
00001 pawan kumar student
******************************** Bottom of Data ****************************
Input Record Layout -
01 INPUT-REC.
05 ID PIC X(05).
05 FILLER PIC X(05).
05 NAME PIC X(15).
05 FILLER PIC X(05).
05 OCCUPATION PIC X(10).
05 FILLER PIC X(40).
JCL -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Job-card
//********************************************************************
//*
//* SORT TO WRITE NUMBERIC TEST IN INCLUDE CONDITION
//*
//********************************************************************
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=MTH.SORT.INPUT,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
INCLUDE COND=(1,05,CH,EQ,C'00001')
SORT FIELDS=COPY
/*
**************************** Bottom of Data **************************
Output -
----+----1----+----2----+----3---+----4---+----5---+----6---+----7---+----8
********************************* TOP OF DATA *******************************
00001 Pawan kumar Student
******************************** BOTTOM OF DATA ****************************
Explaining Example -
- As a first step, need to get the position of the ID in the file.
- The ID starting from 1st position and ends at 5th position as per the input record layout provided. So the length of ID field is 5.
- As a second step, need to get the type of the ID.
- From the Input record layout declaration, ID field is alpha-numeric. So the type is character (CH).
- Lastly, the job requirement is to filter the data with the ID as 00001. So the constant is 00001.
- The INCLUDE condition for the above requirement with all the data gathered is
- The above condition specifies that include the records where the ID is 00001 and copied to output file.
- The output would have the records where the IDs had 00001 at first 5 positions.
INCLUDE COND=(1,05,CH,EQ,C'00001')