subtract date from file



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

subtract date from file

Postby pulcinella » Fri Jan 20, 2012 1:14 am

Hello anyone

I recently read post where people wondered how to subtract days to a date in a file. My question is, if I can subtract one date (as a parameter in the JCL) to another date within a file. I mean.

I have a file with many dates (yyyymmdd format). I need to subtract this date to another introduced by CONTROL-M (yyyymmdd format) and take the difference of days in another file.

I have the following dates in a file (fb=8)

20110112
20110114
20110320
20110322
20110512
.....

I want subtract one date (for example 20120131) to all records. My output file should be the difference in days (fb=8)

-10019
-10017
-9811
-9809
-9619
.....

How I can do? I also want to make the sign... I use ICE201I DFSORT (October, 2010 DFSORT functions)

Thanks a lot of
pulcinella
 
Posts: 114
Joined: Mon Dec 10, 2007 10:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: subtract date from file

 

Re: subtract date from file

Postby skolusu » Fri Jan 20, 2012 2:00 am

pulcinella wrote:My output file should be the difference in days (fb=8)


Your requirements do not match your output. The difference between 20110112 and 20120131 is -0000384 days and not 1 year 19 days.

With PTF UK90025 for z/OS DFSORT V1R10 and PTF UK90026 for z/OS DFSORT V1R12(Oct, 2010), DFSORT now supports date arithmetic which can be used to calculate the number of days difference between two dates. The result is an 8-byte value consisting of a sign and 7 digits (sddddddd). If the first date is greater than or equal to the second date, the sign is + (plus). If the first date is less than the second date, the sign is - (minus).

//   SET CNTMDATE='20120131'                                 
//STEP0100 EXEC PGM=SORT,PARM='JP1"&CNTMDATE"'               
//SYSOUT   DD SYSOUT=*                                       
//SORTIN   DD *                                               
20110112                                                     
20110114                                                     
20110320                                                     
20110322                                                     
20110512                                                     
//SORTOUT  DD SYSOUT=*                                       
//SYSIN    DD *                                               
  SORT FIELDS=COPY                                           
  INREC IFOUTLEN=8,IFTHEN=(WHEN=INIT,OVERLAY=(10:JP1)),       
  IFTHEN=(WHEN=INIT,BUILD=(1,8,Y4T,DATEDIFF,10,8,Y4T))       
//*


The output of this is
-0000384
-0000382
-0000317
-0000315
-0000264


For complete details of date arithmetic functions and other new functions see "User Guide for DFSORT PTFs UK90025 and UK90026" paper (sortugph.pdf) at:

http://www.ibm.com/support/docview.wss? ... g3T7000242
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
skolusu
 
Posts: 586
Joined: Wed Apr 02, 2008 10:38 pm
Has thanked: 0 time
Been thanked: 39 times

Re: subtract date from file

Postby Akatsukami » Fri Jan 20, 2012 2:34 am

skolusu wrote:
pulcinella wrote:My output file should be the difference in days (fb=8)


Your requirements do not match your output. The difference between 20110112 and 20120131 is -0000384 days and not 1 year 19 days.

pulcinella did a naÏve (and erroneous) subtraction, treating the dates as if they were decimal numbers. 20110112 - 20120131 (i.e., 20,110,112 - 20,120,131) is in fact -10,019; 2011/01/12 - 2012/01/31 is -384 days.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1054
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: subtract date from file

Postby pulcinella » Fri Jan 20, 2012 11:26 am

skolosu, Akatsukami,

you are right. Wrong to make the other days. Indeed they are -384, -382, -317 and so on. Apologies for the small error. I'll try what you say and I will comment. thanks
pulcinella
 
Posts: 114
Joined: Mon Dec 10, 2007 10:18 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post