|
View previous topic :: View next topic
|
| Author |
Message |
joeempson
New User
Joined: 21 Mar 2009 Posts: 11 Location: UK
|
|
|
|
I want to include records in my sort which have a date within the last year.
The input file has a date in the format YYYY-MM-DD
| Code: |
2008-10-01 RECORD 01
2009-10-02 RECORD 02
2010-12-03 RECORD 03
2011-05-05 RECORD 04
|
I have come up with this solution
| Code: |
INCLUDE COND=(1,10,CH,GE,DATE1(-)-365)
|
This works fine but does not cater for leap years when the date calculation should be DATE1(-)-366.
I have come up with various complicated solutions for this but I'm keep to keep the code as simple as possible. Is there a simple solution?
Thanks for any help. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
What does the user want? Sometimes we are too "literal" about things. You might get lucky.
Perhaps if you can convert 60th day of the year to a date, then see if it is Feb 29 or not? Then one or t'other. |
|
| Back to top |
|
 |
joeempson
New User
Joined: 21 Mar 2009 Posts: 11 Location: UK
|
|
|
|
I hear what you're saying and in fact this is not specifically for a user requirement. It came out of some analysis I was doing and I just wanted to make sure that I haven't missed the DATE1(-)-1year function
 |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
joeempson,
Use the following DFSORT JCL which will give you the desired results. I assumed that your input is FB recfm and LRECL=80
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
2008-10-01 RECORD 01
2009-10-02 RECORD 02
2010-12-03 RECORD 03
2011-05-05 RECORD 04
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC OVERLAY=(81:DATE1,81,8,Y4T,SUBYEARS,+1,TOGREG=Y4T(-))
OUTFIL BUILD=(1,80),INCLUDE=(1,10,CH,GE,89,10,CH)
//* |
SUBYEARS function subtracts n years from the p,m,Yxx date field. If the resulting date is February 29 of a non-leap year, it will be adjusted backwards to a valid date of February 28. ex :
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
20090228
20080229
20100228
20110228
20120229
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC OVERLAY=(30:1,8,Y4T,SUBYEARS,+1,TOGREG=Y4T(-),
45:1,8,Y4T,SUBDAYS,+365,TOGREG=Y4T(-))
//* |
Using leap year and non leap year dates you can see how the date is adjusted when using the SUBYEARS function vs subtracting 365 days.
| Code: |
20090228 2008-02-28 2008-02-29
20080229 2007-02-28 2007-03-01
20100228 2009-02-28 2009-02-28
20110228 2010-02-28 2010-02-28
20120229 2011-02-28 2011-03-01
|
|
|
| Back to top |
|
 |
joeempson
New User
Joined: 21 Mar 2009 Posts: 11 Location: UK
|
|
|
|
That's perfect !!
Exactly what I needed. Thank you |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|