Page 1 of 1

Date Difference.

PostPosted: Wed Aug 29, 2012 7:42 pm
by Vineet
Hi All,

I am having a Sequential Having LRECL = 1060 & RECFM = FB. There are 2 Date Fields in the Record. I Would Like to Take the Difference of the Date & Write all Records from Input File Along with Date Difference. Below are the Required Attribute of I/P File & O/P File. How Can this is be Achieved using SORT.

I/P File: LRECL = 1060, RECFM = FB
O/P File: LRECL = 1064, RECFM = FB

Example:
I/P File:
AA 1233456 AAAABBBB12 33AAAAAAAAA 777788PPP 2012-08-29 KEEPIN OUTREC POGO MAINFRAME 2012-09-10 ......... 

Date1 = 2012-08-29, Length = 10, Start Pos = 46
Date2 = 2012-09-10, Length = 10, Start Pos = 86

O/P File:
AA 1233456 AAAABBBB12 33AAAAAAAAA 777788PPP 2012-08-29 KEEPIN OUTREC POGO MAINFRAME 2012-09-10 .........  0013

0013 = Date2 - Date1. All Remaning Fields are Same. Date Difference Field To Appear as Last Field of the Record.

Thanks
Kind Rgd's

Re: Date Difference.

PostPosted: Wed Aug 29, 2012 10:44 pm
by skolusu
vineet,

You can calculate the difference between 2 dates using DATEDFIFF function.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).

Your output shows that you wanted only 4 bytes. what happens if the date difference exceeds 9999? Also 2012-09-10 - 2012-08-29 = 12 days but you show it as 13 days.

Assuming that your input dates start at position 45 for a length of 10 and position 85 for a length of 10, you can use the following DFSORT JCL
//STEP0100 EXEC PGM=SORT                             
//SYSOUT   DD SYSOUT=*                               
//SORTIN   DD DISP=SHR,DSN=Your Input FB 1060 file         
//SORTOUT  DD SYSOUT=*                               
//SYSIN    DD *                                       
  SORT FIELDS=COPY                                   
  INREC IFOUTLEN=1068,IFTHEN=(WHEN=INIT,             
        OVERLAY=(1070:45,10,UFF,M11,LENGTH=8,         
                 1080:85,10,UFF,M11,LENGTH=8,         
                 1061:1080,8,Y4T,DATEDIFF,1070,8,Y4T))
//*

Re: Date Difference.

PostPosted: Thu Aug 30, 2012 12:41 am
by Vineet
Hi Kolusu,

Thanks for the Help,It's Working. Regarding UR Queries What If difference Exceeds 9999, It's Very Rare Or can say Not Possible. Now Regarding the Difference 2012-09-10 - 2012-08-29 = 12 days but you show it as 13 days. Reason for Showing 13 as Our Start Date is 2012-09-10 & We'll Start Counting Number of Days from 2012-09-10. Now to Get Result i.e. Difference as 13 what Change is Required.
Can U suggest any Website from where I can Get Meaning of Y4T, UFF,M11, INIT etc.....

Thanks
Kind Rgd's

Re: Date Difference.

PostPosted: Thu Aug 30, 2012 1:12 am
by BillyBoyo
Have a look at Kolusu's signature.

Re: Date Difference.

PostPosted: Thu Aug 30, 2012 1:14 am
by dick scherrer
Hello,

At the top and bottom of the page is a link to "IBM Manuals". The DFSORT documentation is available there also.

Re: Date Difference.

PostPosted: Thu Aug 30, 2012 1:15 am
by steve-myers
Vineet wrote:... Regarding UR Queries What If difference Exceeds 9999, It's Very Rare Or can say Not Possible. ...
  • Please don't use SMS codes like UR in this forum
  • In our trade one should be extremely careful about saying something is impossible. August 29, 2012 - 9999 days is April 14, 1985. There should be little harm in allocating an extra byte.

Re: Date Difference.

PostPosted: Thu Aug 30, 2012 1:23 am
by Akatsukami
steve-myers wrote:
Vineet wrote:... Regarding UR Queries What If difference Exceeds 9999, It's Very Rare Or can say Not Possible. ...
  • In our trade one should be extremely careful about saying something is impossible. August 29, 2012 - 9999 days is April 14, 1985. There should be little harm in allocating an extra byte.

9,999 days is a little more than 27 years. The TS is probably younger than that :geek:

Re: Date Difference.

PostPosted: Thu Aug 30, 2012 1:43 am
by enrico-sorichetti
Reason for Showing 13 as Our Start Date is 2012-09-10 & We'll Start Counting Number of Days from 2012-09-10.

c /2012-09-10/2012-08-29/

0013 = Date2 - Date1.


wiser to change the terminology ... form a date mathematics point of view the result is 12 ....
the date difference <2012-09-10> - <2012-09-09> is 1(ONE)

what You are requesting is something specific to Your organization so before complaining
You should describe/explain better Your terminology

anyway just add one to the computed TRUE difference

Re: Date Difference.

PostPosted: Thu Aug 30, 2012 2:02 am
by skolusu
Vineet wrote:Hi Kolusu,
Can U suggest any Website from where I can Get Meaning of Y4T, UFF,M11, INIT etc.....


If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:

http://www.ibm.com/support/docview.wss? ... g3T7000080

Vineet wrote:Hi Kolusu,
Reason for Showing 13 as Our Start Date is 2012-09-10 & We'll Start Counting Number of Days from 2012-09-10. Now to Get Result i.e. Difference as 13 what Change is Required.


As enrico pointed , you are doing something special . Assuming that your DATE2 is always greater than Date1, making the difference a positive value, you can use the following SYSIN to add +1 to the difference.

//SYSIN    DD *                                                     
  SORT FIELDS=COPY                                                   
  INREC IFOUTLEN=1068,IFTHEN=(WHEN=INIT,                             
        OVERLAY=(1070:45,10,UFF,M11,LENGTH=8,                       
                 1080:85,10,UFF,M11,LENGTH=8,                       
                 1061:1080,8,Y4T,DATEDIFF,1070,8,Y4T,               
                 1061:1061,8,SFF,ADD,+1,EDIT=(STTTTTTT),SIGNS=(+,-)))
//*

Re: Date Difference.

PostPosted: Thu Aug 30, 2012 3:23 am
by Akatsukami
skolusu wrote:As enrico pointed , you are doing something special .

Not that special; he is using the word "difference" instead of "count".