Date Difference.



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

Date Difference.

Postby Vineet » Wed Aug 29, 2012 7:42 pm

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
Vineet
 
Posts: 86
Joined: Tue Jun 19, 2007 11:38 am
Has thanked: 0 time
Been thanked: 0 time

Re: Date Difference.

Postby skolusu » Wed Aug 29, 2012 10:44 pm

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))
//*
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: Date Difference.

Postby Vineet » Thu Aug 30, 2012 12:41 am

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
Vineet
 
Posts: 86
Joined: Tue Jun 19, 2007 11:38 am
Has thanked: 0 time
Been thanked: 0 time

Re: Date Difference.

Postby BillyBoyo » Thu Aug 30, 2012 1:12 am

Have a look at Kolusu's signature.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Date Difference.

Postby dick scherrer » Thu Aug 30, 2012 1:14 am

Hello,

At the top and bottom of the page is a link to "IBM Manuals". The DFSORT documentation is available there also.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Date Difference.

Postby steve-myers » Thu Aug 30, 2012 1:15 am

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.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Date Difference.

Postby Akatsukami » Thu Aug 30, 2012 1:23 am

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:
"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: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Date Difference.

Postby enrico-sorichetti » Thu Aug 30, 2012 1:43 am

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Date Difference.

Postby skolusu » Thu Aug 30, 2012 2:02 am

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=(+,-)))
//*
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: Date Difference.

Postby Akatsukami » Thu Aug 30, 2012 3:23 am

skolusu wrote:As enrico pointed , you are doing something special .

Not that special; he is using the word "difference" instead of "count".
"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: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post