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:-
Requirement: Copy records that has ‘44444’ in position 1 to 5
JCL Code:-
Output file:-
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:-
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:
Output file:-
Example 2:-
Input file:-
Requirement: Copy records which has date between CURRENT DATE +/- 10 days (let’s assume current date is 2016-Aug-11)
SYSIN Control card:
Output file:-
Tip: If input date format is YYYY-MM-DD, use DATE1(-) in place of DATE1.
Example 3:-
Input file:-
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:
Output file:-
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:
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:
Requirement 3: To copy only those records which has valid numeric data in specified fields
SYSIN Control card:
Requirement 4: To copy only those records which has valid numeric data in specified fields
SYSIN Control card: