Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 8: JCL Sort & Merge


INCLUDE Statement

INCLUDE statement is used to select only specific records which meet specified criteria. INCLUDE statement provide us flexibility to select only few records by specifying conditions which can:-

  • Compare field with some value
  • Compare two fields of the file
  • Compare fields value with date, numeric, alphanumeric, character
  • Search the constant within field
  • Compare one field value with multiple values
  • Check if a particular field format is numeric, non-numeric, signed zoned decimal, signed packed decimal

Syntax:-

Let’s see example:-

Input file:-

----+----1----+----2----+----3----+----4----+----5 88888JOHN PURCHASING 08000 11111AKSHAY HR 10000 55555SMITH R&D 25000 44444STEVE ADMIN 20000 33333VIJAY FINANCE DEPT 24000 77777VIJAY FINANCE DEPT 30000 44444STEVE HR 20000

Requirement: Copy records that has ‘44444’ in position 1 to 5

JCL Code:-

//SORTSTEP EXEC PGM=SORT //SORTIN DD DSN=DEPT.EMPL.DATA.INPUT, // DISP=SHR //SORTOUT DD DSN=DEPT.EMPL.DATA.OUTPUT1, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=50,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD * SORT FIELDS=COPY INCLUDE COND=(1,5,CH,EQ,C'44444') /*

Output file:-

----+----1----+----2----+----3----+----4----+----5 44444STEVE ADMIN 20000 44444STEVE HR 20000

We will show you few more example once concept of ‘Using Date constant in SORT INCLUDE statement’ is explained

Using Date Constant in INCLUDE statement

In order to deal with conditions which involves date comparison, INCLUDE statement is provided with few Date constants which can help us to specify and use current date, past date or any future dates.

To specify current date one can use below constants based on the format needed:-

System provided constant Format of date
DATE1P +YYYYMMDD
DATE2P +YYYYMM
DATE3P +YYYYDDD

  • All constants i.e. DAT1P, DATE2P and DATE3P refers to current date, current month and current day of year respectively
  • Past date can be referred by subtracting any number of days from constant i.e. (DATE1P-1 refers to yesterday, DAT1P-2 refers to Day before yesterday and so on). Similarly one can also subtract number of months from DATE2P and days from DATE3P.
  • Future date can be referred by adding any number of days to constant i.e. (DATE1P+1 refers to tomorrow, DAT1P+2 refers to Day after tomorrow and so on). Similarly one can also add number of months from DATE2P and days from DATE3P.

Note: Removing the end letter ‘P’ from date constant will allow us to use date constant as character value i.e. DATE1 equals to C’20190110’

Example 1:-

Input file:-

----+----1----+----2----+----3----+----4----+----5 11111AKSHAY HR 10000 20250811 44444STEVE HR 20000 20120811 11111AKSHAY HR 10000 20150811 55555SMITH R&D 25000 20150811 44444STEVE ADMIN 20000 20160805 77777VIJAY FINANCE DEPT 30000 20160815 44444STEVE HR 20000 20240811

Requirement: Copy records which has date less than or same as current date (let’s assume current date is 2016-Aug-11)

SYSIN Control card:

//SYSIN DD * SORT FIELDS=COPY INCLUDE COND=(43,8,ZD,LE,DATE1P) /*

Output file:-

----+----1----+----2----+----3----+----4----+----5 44444STEVE HR 20000 20120811 11111AKSHAY HR 10000 20150811 55555SMITH R&D 25000 20150811 44444STEVE ADMIN 20000 20160805

Example 2:-

Input file:-

----+----1----+----2----+----3----+----4----+----5 11111AKSHAY HR 10000 20250811 44444STEVE HR 20000 20120811 11111AKSHAY HR 10000 20150811 55555SMITH R&D 25000 20150811 44444STEVE ADMIN 20000 20160805 77777VIJAY FINANCE DEPT 30000 20160815 44444STEVE HR 20000 20240811

Requirement: Copy records which has date between CURRENT DATE +/- 10 days (let’s assume current date is 2016-Aug-11)

SYSIN Control card:

//SYSIN DD * SORT FIELDS=COPY INCLUDE COND=(43,8,ZD,LE,DATE1P+10,AND,43,8,ZD,GE,DATE1P-10) /*

Output file:-

----+----1----+----2----+----3----+----4----+----5 44444STEVE ADMIN 20000 20160805 77777VIJAY FINANCE DEPT 30000 20160815

Tip: If input date format is YYYY-MM-DD, use DATE1(-) in place of DATE1.

Example 3:-

Input file:-

----+----1----+----2----+----3----+----4----+----5 11111AKSHAY HR 10000 2025-08-11 44444STEVE HR 20000 2012-08-11 11111AKSHAY HR 10000 2015-08-11 55555SMITH R&D 25000 2015-08-11 44444STEVE ADMIN 20000 2015-08-11 77777VIJAY FINANCE EPT 30000 2024-08-11 44444STEVE HR 20000 2024-08-11

Requirement: Copy records which has date greater than or same as current date. Here date format is YYYY-MM-DD (let’s assume current date is 2016-Aug-11)

SYSIN Control card:

//SYSIN DD * SORT FIELDS=COPY INCLUDE COND=(43,8,CH,GE,DATE1(-)) /*

Output file:-

----+----1----+----2----+----3----+----4----+----5 11111AKSHAY HR 10000 2025-08-11 77777VIJAY FINANCE EPT 30000 2024-08-11 44444STEVE HR 20000 2024-08-11

Below are few more requirement which can be addressed using SORT INCLUDE command:

Requirement 1: To copy only those records which has one of the values (‘STEVE’,’VIJAY’,’SMITH’) in position 6 to 10

SYSIN Control card:

INCLUDE COND=(6,5,SS,EQ,C'STEVE,VIJAY,SMITH')

Requirement 2: To copy only those records which has value at position 72-76 greater than or equal to 1000 or less than 10

SYSIN Control card:

INCLUDE COND=(72,5,PD,GE,1000,OR,72,5,PD,LT,10)

Requirement 3: To copy only those records which has valid numeric data in specified fields

SYSIN Control card:

INCLUDE COND=(50,10,FS,EQ,NUM)

Requirement 4: To copy only those records which has valid numeric data in specified fields

SYSIN Control card:

INCLUDE COND=(50,10,FS,EQ,NUM)







© copyright mainframebug.com
Privacy Policy