Using SORT DATE Functions you can dynamically insert the date, like ‘yyyy-mm-dd’ or any format instead of a constant date like ‘2021-01-01’. There are multiple Date Functions by which you can reformat input dates. By using INREC, OUTREC, and OUTFIL statements to insert the current date or past date, or future date in a variety of formats and time in a variety of formats into your records.
Current Date Format | Format of Constant | Example of Constant |
DATE1 | C’yyyymmdd’ | C’20050621′ |
DATE1(c) | C’yyyycmmcdd’ | C’2005/06/21′ |
DATE2 | C’yyyymm’ | C’200506′ |
DATE2(c) | C’yyyycmm’ | C’2005/06′ |
DATE3 | C’yyyyddd’ | C’2005172′ |
DATE3(c) | C’yyyycddd’ | C’2005/172′ |
DATE4 | C’yyyy-mm-dd-hh.mm.ss’ | C’2005-06-21-16.52.45′ |
DATE4 | C’yyyy-mm-dd-hh.mm.ss’ | C’2005-06-21-16.52.45′ |
DATE5 | C’yyyy-mm-dd-hh.mm.ss.nnnnnn’ | C’2005-06-21-16.52.45.582013′ |
Both the DATE1(c) and DATE=(4MDc) operands correspond to a C’yyyycmmcdd’ constant for today’s date where c is any separator character you like except blank. So either of the following pairs of control statements will sort your records on input positions 1-6 and reformat them with today’s date in the form C’yyyy-mm-dd’ in output positions 1-10, and input positions 1-6 in output positions 11-16.
SORT FIELDS=(1,6,CH,A),FORMAT=CH OUTREC BUILD=(1:DATE1(-),11:1,6)
OR
SORT FIELDS=(1,6,CH,A),FORMAT=CH OUTREC BUILD=(1:DATE=(4MD-),11:1,6)
You could insert the current time as well as the current date in your records to produce a timestamp.
For example: OUTREC BUILD=(DATE3,TIME1,1,6) would produce a character timestamp in output positions 1-12 of the form: yyyydddhhmmss
More easily, you could use DATE4 to produce a timestamp of the form: yyyy-mm-dd-hh.mm.ss or DATE5 to produce a timestamp with microseconds of the form: yyyy-mm-dd-hh.mm.ss.nnnnnn
Date constants can be produced in a variety of other characters, zoned decimal and packed decimal formats as well such as C’yyyy-mm’, Z’yyyymmdd’ and P’yyddd’. Time constants can also be produced in a variety of other characters, zoned decimal and packed decimal formats as well such as C’hh:mm’, Z’hhmmssxx’ and P’hhmmss’.
If, as in the second question above, you wanted to produce just one record containing the date, you could select from a variety of date formats.
For example, if you wanted to create a record with just C’dddyy’, you could do it with OUTREC as follows:
//DATERCD EXEC PGM=ICEMAN //SYSOUT DD SYSOUT=* //SORTIN DD * DUMMY RECORD //SORTOUT DD DSN=... //SYSIN DD * OPTION COPY OUTREC BUILD=(YDDDNS=(DY)) /*
Let’s say we have a C’yyyymmdd’ date field starting at position 10 of each record. Each day we want only the records for that day to be copied into the output file.
INCLUDE and OMIT statements can be used to select records using a variety of formats for today’s date like C’yyyymmdd’, C’yyyy/mm/dd’, +yyyymmdd, C’yyyyddd’, C’yyyy/ddd’, +yyyyddd, C’yymmdd’ and so on.
The DATE1 operand corresponds to a C’yyyymmdd’ constant for today’s date. So the following control statement will include only those records with a C’yyyymmdd’ date in positions 10-17 equal to today’s date:
INCLUDE COND=(27,8,CH,EQ,DATE1)
Some other examples:
Of course, you can use the other comparison operators (NE, GT, GE, LT, LE) as well as EQ. For example, you could use GT to select records with dates after today, or LT to select records with dates before today.
Let’s say we have a file with a date in a particular position and we want to select only records where the date is greater than the current or a particular date + or – N number of days and it can be 0 to 9999. Let’s assume N is 30 days.
You can use INCLUDE and OMIT to select records using a variety of formats for past and future dates like C’yyyymmdd’, C’yyyy/mm/dd’, +yyyymmdd, C’yyyyddd’, C’yyyy/ddd’, +yyyyddd, C’yymmdd’ and so on.
The DATE1(-)-30 operand corresponds to a C’yyyy-mm-dd’ constant for today’s date minus 30 days. So the following control statement will include only those records with a C’yyyy-mm-dd’ date in positions 14-23 greater than today’s date – 30 days.
INCLUDE COND=(14,10,CH,GT,DATE1(-)-30)
Some other examples:
Example
Input file 10 suresh 20000 01 20120203 20 NARENDRA 40000 06 20110925 30 jacob A 25000 07 20111018 40 RAMESH 34000 03 20120410 50 Kishore 50000 02 20130408
INCLUDE in SORT - selecting the records between the two dates. //SYSIN DD * SORT FIELDS=COPY INCLUDE COND=(22,8,ZD,LE,DATE1P+10,AND,22,8,ZD,GE,DATE1P-10) /*
Explanation – In the above example, the SORT card will select the records, if the date in the input
record is between the current date +/- 10days. Selected records will be copied to the output file.
Output file for SORT JCL – Assume the current date is – 4-Apr-2012.
Following records will be selected from the input file.
40 RAMESH 34000 03 20120410 50 Kishore 50000 02 20120408
A well-maintained product backlog is crucial for successful product development. It serves as a single…
Incremental value to the customer refers to the gradual delivery of small, functional parts of…
A Product Market refers to the group of potential customers who might be interested in…
The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…
The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…
Choosing the right Scrum Master Certification depends on your current experience and career goals. If…