Due to huge data in the input file I want to extract only those records with current year in the first date field. It is in the format '2016/01/01'.
I want to do this by comparing the first 4 positions of the file to current year, current month and current date individually.
Please advise how to achieve this using sort card.
Input
2014mmdd
2015mmdd
2016mmdd
Output should be the records of the current year like below.
2016mmdd
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
If you want a sort solution why post in JCL & VSAM? Why didn't you post in the relevant sort sub-section of the forum. Also provide the full information re the dataset - RECFM, LRECL and representative data showing if duplicates could be present and whether they are in sort sequence or not.
Moving to DFSort but if you use Syncsort then say so and it will be moved there.
//SORTIN DD *
20160316 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
//DACCYYMM EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,6,CH,EQ,DATE1)
//SORTIN DD *
20160316 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
//DACCYYMM EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,8,CH,EQ,DATE1)
//SORTIN DD *
20160316 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
//DATECCYY EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,4,CH,EQ,DATE1(/))
//SORTIN DD *
2016/03/16 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
//DACCYYMM EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,6,CH,EQ,DATE1(/))
//SORTIN DD *
2016/03/16 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
//DACCYYMM EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,8,CH,EQ,DATE1(/))
//SORTIN DD *
2016/03/16 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
Run that lot, and look at the SORTOUTs in the spool.
You will see
Code:
20160316 THIS ONE
as output from the first three steps, and
Code:
2016/03/16 THIS ONE
as output from the last three steps.
For those who not only don't run the suggested code, but don't read the suggested manual either:
Quote:
Tip: When a field is shorter than the character string it's compared to, DFSORT truncates the string on the right. You can take advantage of this to compare a field to only part of the DATE4 timestamp when appropriate. For example:
INCLUDE COND=(1,13,CH,GT,DATE4)
would compare the field in positions 1-13 to the truncated DATE4 constant C'yyyy-mm-dd-hh'.
What works with DATE4 in the example is not specific to DATE4, it works with all the date constants, edited or not.
If it is the current year and month, sort symbolics utilizing system symbolics.
Code:
CCYY,S'&LYR4'
CCYYMM,S'&LYR4.&LMON'
------------------ SYMBOL TABLE -----------------
CCYY,C'2016'
CCYYMM,C'201603'
If you want to use a previous date range, generate your own symbolics to be used in the sort step. You could configure to use them as a passed exec parm so that you can override the values as you need to.
Code:
// SET OBCDATE='CCYYMM'
//********************************************************
//* GENERATE DATE PARMS FOR DATA EXTRACTION
//********************************************************
//STEP0001 EXEC PGM=SORT,PARM=('JP0"&OBCDATE"')
//SYSOUT DD SYSOUT=*
//SORTIN DD *
CCYYMM MMCCYY MMDDCCYY CCYYDDD
//DATEPARM DD DSN=&&S,DISP=(,PASS,DELETE),UNIT=SYSDA,SPACE=(TRK,(1,1))
//DATEPARX DD SYSOUT=*
//SYSIN DD *
OPTION COPY,STOPAFT=1
* EDIT TO SEE IF THERE IS A PARM DATE OVERRIDE, OTHERWISE USE DEFAULT
* FOR PREVIOUS MONTH, EXPECTS CCYYMM FORMAT AND CONVERTS TO JULIAN
*
INREC IFOUTLEN=80,
IFTHEN=(WHEN=(1,6,CH,NE,JP0),
OVERLAY=(81:JP0,C'01',81:81,8,Y4T,TOJUL=Y4T,
1:81,7,10:81,7,Y4T,LASTDAYM,TOJUL=Y4T),HIT=NEXT),
IFTHEN=(WHEN=(1,6,CH,EQ,JP0),
OVERLAY=(81:DATE2-1,C'01',81:81,8,Y4T,TOJUL=Y4T,
1:81,7,10:81,7,Y4T,LASTDAYM,TOJUL=Y4T))