z/OS DFSORT Application Programming Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Example 19

z/OS DFSORT Application Programming Guide
SC23-6878-00

  OPTION COPY,Y2PAST=1990                                         
  OUTREC IFTHEN=(WHEN=INIT,                                       
    BUILD=(1:1,8,UFF,TO=ZD,LENGTH=6,8:11,6,UFF,TO=ZD,LENGTH=5)),  
   IFTHEN=(WHEN=INIT,                                             
     BUILD=(1,6,Y2W,DATEDIFF,8,5,Y2T))     

This example illustrates how you can calculate the difference in days between two different types of date fields, each of which has separators.

The SORTIN data set has these input records with a C'mm/dd/yy' date field in positions 1-8 and a C'yy/ddd' date field in positions 11-16:
03/05/07 07/052
12/13/07 08/193
02/19/08 08/365
09/01/08 09/001
11/22/09 09/015
07/22/98 01/121
01/15/09 09/015
09/15/10 09/322
06/30/10 08/050

The OUTREC statement calculates the number of days for date1-date2 and puts the result in the output record in positions 1-8.

The first IFTHEN clause removes the / separators from date1 and date2 so we can use them in DATEDIFF. After the first IFTHEN clause, the records look like this, with the C'mmddyy' date in positions 1-6 and the C'yyddd' date in positions 8-12:
030507 07052
121307 08193
021908 08365
090108 09001
112209 09015
072298 01121
011509 09015
091510 09322
063010 08050

The second IFTHEN clause uses DATEDIFF to get the number of days between date1 and date2. We use 1,6,Y2W to match the C'mmddyy' date and 8,5,Y2T to match the C'yyddd' date.

SORTOUT will have these records:
+0000012
-0000211
-0000315
-0000122
+0000311
-0001014
+0000000
+0000301
+0000862

Note that when date1>=date2, the result is a positive value, and when date1<date2, the result is a negative value.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014