Social Icons

twitter email

Sunday, August 24, 2014

DFSORT - Identify invalid dates

You can use DFSORT's TOGREG or TOJUL functions to identify invalid input dates. Dates with values outside of the valid range (for example, a month not between 01-12) will be shown as asterisks making them easy to identify. For example, if you had the following input records with 'yyyymmdd' dates:
Betten 20091021
Vezinaw 20091101
Casad 00000000
Boenig 20091325
Kolusu 20090931
Yaeger 20090731
You could use these DFSORT control statements to display an additional column with asterisks for any invalid dates:
OPTION COPY
OUTREC OVERLAY=(30:16,8,Y4T,TOGREG=Y4T)
SORTOUT would have these records:
BETTEN 20091021 20091021
VEZINAW 20091101 20091101
CASAD 00000000 00000000
BOENIG 20091325 ********
KOLUSU 20090931 ********
YAEGER 20090731 20090731
If you wanted to display only the records with invalid dates, you could use these DFSORT control statements:
OPTION COPY
OUTREC OVERLAY=(30:16,8,Y4T,TOGREG=Y2T)
OUTFIL INCLUDE=(30,1,CH,EQ,C'*'),BUILD=(1,25)
SORTOUT would then have these records:
BOENIG 20091325
KOLUSU 20090931

Tuesday, August 5, 2014

Convert between different types of dates using DFSORT


DFSORT's TOJUL and TOGREG functions make it easy to convert between various types of Julian, Gregorian,4-digit year, 2-digit year, CH, ZD, and PD dates.

1. The following DFSORT job converts a 'yyyymmdd' date to a 'yyyyddd' date:
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
20090520
20100106
20100921
20081217
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC BUILD=(1,8,Y4T,TOJUL=Y4T)
/*
SORTOUT would have these records:
2009140
2010006
2010264
2008352
2. The following DFSORT job converts a 'yymmdd' date to a 'yyyy-ddd' date:
//S2 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
ABC 090520
DEF 100106
GHI 100921
JKL 081217
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION Y2PAST=1990
SORT FIELDS=(5,6,Y2T,A)
OUTREC OVERLAY=(5:5,6,Y2T,TOJUL=Y4T(-))
/*
SORTOUT would have these sorted records:
JKL 2008-352
ABC 2009-140
DEF 2010-006
GHI 2010-264
3. The following DFSORT job converts a P'dddyyyy' date starting in position 21 to a 'mm-dd-yyyy' date starting in position 51:
//S3 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file
//SORTOUT DD DSN=... output file
//SYSIN DD *
OPTION COPY
OUTFIL OVERLAY=(51:21,4,Y4X,TOGREG=Y4W(-))
/*
Here's an example of the input and converted fields:
21            51
P'2122008' -> 07-30-2008
P'0722010' -> 03-13-2010
4. The following DFSORT job converts a 'yyyy-mm-dd' date to a P'mmddyy' date.
//S4 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
2009-05-20
2010-01-06
2010-09-21
2008-12-17
//SORTOUT DD DSN=... output file
//SYSIN DD *
SORT FIELDS=(1,10,CH,A)
OUTREC IFTHEN=(WHEN=INIT,BUILD=(1,10,UFF,TO=ZD,LENGTH=8)),
IFTHEN=(WHEN=INIT,BUILD=(1,8,Y4T,TOGREG=Y2Y))
/*
Here's what the sorted and converted fields would look like:
P'121708'
P'052009'
P'010610'
P'092110'
5. The following DFSORT job converts a 'mm/dd/yyyy' date to a 'yyyyddd' date:
//S5 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
04/08/2006ABC
11/15/2008DEF
09/30/2010GHI
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OUTREC IFTHEN=(WHEN=INIT,
BUILD=(1,10,UFF,TO=ZD,LENGTH=8,9:11,3)),
IFTHEN=(WHEN=INIT,BUILD=(1,8,Y4W,TOJUL=Y4T,9,3))
/*
SORTOUT would have these records:
2006098ABC
2008320DEF
2010273GHI
 
Blogger Templates