Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Adding one day to a date field YYYYMMDD

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
siva102

New User


Joined: 28 Nov 2007
Posts: 64
Location: Chennai

PostPosted: Thu Aug 05, 2010 8:05 pm    Post subject: Adding one day to a date field YYYYMMDD
Reply with quote

Hi All,

I am having a variable filr of LRECL = 1504. In some specific record i have a date field in the format YYYYMMDD. I need to add one day to those date fields.

IF Value from 1 to 4 column = 1000 and 16 to 3 is ATM then the date value will be present from column no 30. To that Date value we need to add one day.

The input file looks like below,

Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21211s asd jjsa
sdh2892 j23bj24  sdfsdfs gdy5r 567568  6786  697897 69
234kns903 lksdfjk33 jj343434 
1000 sdfsdf dsfATM asjahi23dg20100630dfssfsdf
jh788823 hg21881 8811n 81
1000 sdfsdf dsfasjahi23dg20dfssfsdf
1000 sdfsdf dsfATM asjahi23dg20091231dfssfsdf


In the above file the output should look like below,

Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21211s asd jjsa
sdh2892 j23bj24  sdfsdfs gdy5r 567568  6786  697897 69
234kns903 lksdfjk33 jj343434 
1000 sdfsdf dsfATM asjahi23dg20100701dfssfsdf
jh788823 hg21881 8811n 81
1000 sdfsdf dsfasjahi23dg20dfssfsdf
1000 sdfsdf dsfATM asjahi23dg20100101dfssfsdf


The dates have been changed from 20100630 to 20100701 for the tag 1000.

Could anyone please help me to make it possible.
Back to top
View user's profile Send private message

Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Fri Aug 06, 2010 3:21 am    Post subject: Reply to: Adding one day to a date field YYYYMMDD
Reply with quote

siva102,

With z/OS DFSORT V1R5 PTF UK51706 or z/OS DFSORT V1R10 PTF UK51707 (Nov, 2009), DFSORT now supports date conversion functions(TOGREG,TOJUL) which can perform date arithmetic and give you the desired results in one pass like shown below:

Code:

//STEP0100 EXEC PGM=SORT                                 
//SYSOUT   DD SYSOUT=*                                   
//SORTIN   DD DSN=Your input VB 1504 lrecl file,DISP=SHR
//SORTOUT  DD SYSOUT=*                                   
//SYSIN    DD *                                           
  SORT FIELDS=COPY                                       
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,4,15X,5)),             
  IFTHEN=(WHEN=(20,4,ZD,EQ,1000,AND,35,3,CH,EQ,C'ATM'),   
  OVERLAY=(5:49,8,5,8,Y4T,TOJUL=Y4T),HIT=NEXT),           
  IFTHEN=(WHEN=(13,1,CH,GT,C' ',AND,9,4,CH,LT,C'1231'),   
  OVERLAY=(17:17,3,ZD,ADD,+1,EDIT=(TTT),                 
           05:13,7,Y4T,TOGREG=Y4T,49:5,8)),               
  IFTHEN=(WHEN=(9,4,CH,EQ,C'1231'),                       
  OVERLAY=(13:13,4,ZD,ADD,+1,EDIT=(TTTT),C'001',         
           05:13,7,Y4T,TOGREG=Y4T,49:5,8))
               
  OUTFIL BUILD=(1,4,20)                                   
//*
Back to top
View user's profile Send private message
siva102

New User


Joined: 28 Nov 2007
Posts: 64
Location: Chennai

PostPosted: Fri Aug 06, 2010 9:12 pm    Post subject:
Reply with quote

Hi Kolusu,

Thanks for the help. It really worked out for me.

But i do have some other file where i tried implementing the same logic but unable to get the output.

I have two input files and one is like below,

For FILE -1

The input file is a FB of lrcl = 320. And we need to change the date field in two places. The conditions are like below,

If
1 to 3 character = AAA then one date field starts from 40th position and the second date starts from 48th position and these dates need to be added one day.

The input file looks like below,
Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21211s asd jjsa
sdh2892 j23bj24  sdfsdfs gdy5r 567568  6786  697897 69
234kns903 lksdfjk33 jj343434 
AAA0 sdfsdf dsfATM asjahi23dgasjhurjotk2010063020100805dfssfsdf
jh788823 hg21881 8811n 81
1000 sdfsdf dsfasjahi23dg20dfssfsdf
AAA0 sdfsdf dsfATM asjahi23dgahithugjnh2009123120100607dfssfsdf


and the output to that will come like below,

Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21211s asd jjsa
sdh2892 j23bj24  sdfsdfs gdy5r 567568  6786  697897 69
234kns903 lksdfjk33 jj343434 
AAA0 sdfsdf dsfATM asjahi23dgasjhurjotk2010070120100806dfssfsdf
jh788823 hg21881 8811n 81
1000 sdfsdf dsfasjahi23dg20dfssfsdf
AAA0 sdfsdf dsfATM asjahi23dgahithugjnh2010010120100608dfssfsdf



For FILE -2

The input file is a FB of lrcl = 190. And we need to change the date field in three places. The conditions are like below,

If
1 to 3 character = AAA then one date field starts from 20th position and the second date starts from 30th position and the third one from 40th pos and to those we need to add one day.

We have one more condition here is from these three dates sometimes we can have 00000000 instead of any date. And we dont need to change anything in that case.

The input file looks like below,
Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21211s asd jjsa
sdh2892 j23bj24  sdfsdfs gdy5r 567568  6786  697897 69
234kns903 lksdfjk33 jj343434 
AAA0 sdfsdf dsfabc a20090304jh20100103rs00000000jh
1000 sdfsdf dsfasjahi23dg20dfssfsdf
AAA0 sdfsdf dsfabc a20090506jh20100103rs20100908jh


and the output to that will come like below,
Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21211s asd jjsa
sdh2892 j23bj24  sdfsdfs gdy5r 567568  6786  697897 69
234kns903 lksdfjk33 jj343434 
AAA0 sdfsdf dsfabc a20090305jh20100104rs00000000jh
1000 sdfsdf dsfasjahi23dg20dfssfsdf
AAA0 sdfsdf dsfabc a20090507jh20100104rs20100909jh


Could you please help me to make it possible for me.

Thanks in advance.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Fri Aug 06, 2010 10:23 pm    Post subject: Reply to: Adding one day to a date field YYYYMMDD
Reply with quote

siva102,

It would be of a great help for me if you had provided all the details at once. The manipulation of VB files is different from that of FB files. As VB files can have records with different lengths , we need to preserve them by adding the temp fields at the beginning of the record after the RDW.

For FB files we can add the temp fields at the end. so a solution for a VB file may not be applied for a FB file as is.

You need to understand the logic first and then you can customize to any format file.

The logic is quite simple. In order to add a day to existing date

1.we need to convert the Gregorian date (CCYYMMDD) into Julian date(CCYYDDD) ( ddd= day of year) . This is done by the function TOJUL

2. Add +1 to the DDD portion

3. Now you have to perform the reverse of step 1 which is converting the Julian date to Gregorian date. This is done by the function TOGREG.

However there is a loophole with this approach when the date is December 31st. adding 1 day would make it invalid day of the year. so in that case we increment the year by 1 and set the day of the year to 1 and perform step 3.

That is why you have an additional IFTHEN statements checking if the date is December 31st.

The following DFSORT JCL will give you the desired results.

Each date needs 2 IFTHEN statements.

Code:

//STEP0100 EXEC PGM=SORT                                 
//SYSOUT   DD SYSOUT=*                                   
//SORTIN   DD DSN=Your input FB 320 lrecl file,DISP=SHR
//SORTOUT  DD SYSOUT=*                                   
//SYSIN    DD *
  SORT FIELDS=COPY                                                 
  INREC IFOUTLEN=320,                                             
  IFTHEN=(WHEN=(1,3,CH,EQ,C'AAA',AND,44,4,CH,NE,C'1231'),         
  OVERLAY=(321:40,8,Y4T,TOJUL=Y4T,                                 
           325:325,3,ZD,ADD,+1,EDIT=(TTT),                         
           040:321,7,Y4T,TOGREG=Y4T),HIT=NEXT),                   
  IFTHEN=(WHEN=(1,3,CH,EQ,C'AAA',AND,44,4,CH,EQ,C'1231'),         
  OVERLAY=(321:40,4,ZD,ADD,+1,EDIT=(TTTT),C'001',                 
           040:321,7,Y4T,TOGREG=Y4T),HIT=NEXT),                   
                                                                   
  IFTHEN=(WHEN=(1,3,CH,EQ,C'AAA',AND,52,4,CH,NE,C'1231'),         
  OVERLAY=(331:48,8,Y4T,TOJUL=Y4T,                                 
           335:335,3,ZD,ADD,+1,EDIT=(TTT),                         
           048:331,7,Y4T,TOGREG=Y4T),HIT=NEXT),                   
  IFTHEN=(WHEN=(1,3,CH,EQ,C'AAA',AND,52,4,CH,EQ,C'1231'),         
  OVERLAY=(331:48,4,ZD,ADD,+1,EDIT=(TTTT),C'001',                 
           048:331,7,Y4T,TOGREG=Y4T))                     
//*



Second job:

Code:

//STEP0200 EXEC PGM=SORT                                 
//SYSOUT   DD SYSOUT=*                                   
//SORTIN   DD DSN=Your input FB 190 lrecl file,DISP=SHR
//SORTOUT  DD SYSOUT=*                                   
//SYSIN    DD *
  SORT FIELDS=COPY                                             
  INREC IFOUTLEN=190,                                         
  IFTHEN=(WHEN=(01,3,CH,EQ,C'AAA',AND,24,4,CH,NE,C'1231',AND,   
                20,8,CH,NE,C'00000000'),                       
  OVERLAY=(191:20,8,Y4T,TOJUL=Y4T,                             
           195:195,3,ZD,ADD,+1,EDIT=(TTT),                     
           020:191,7,Y4T,TOGREG=Y4T),HIT=NEXT),               
  IFTHEN=(WHEN=(1,3,CH,EQ,C'AAA',AND,24,4,CH,EQ,C'1231'),     
  OVERLAY=(191:20,4,ZD,ADD,+1,EDIT=(TTTT),C'001',             
           020:191,7,Y4T,TOGREG=Y4T),HIT=NEXT),               
                                                               
  IFTHEN=(WHEN=(01,3,CH,EQ,C'AAA',AND,34,4,CH,NE,C'1231',AND,   
                30,8,CH,NE,C'00000000'),                       
  OVERLAY=(201:30,8,Y4T,TOJUL=Y4T,                             
           205:205,3,ZD,ADD,+1,EDIT=(TTT),                     
           030:201,7,Y4T,TOGREG=Y4T),HIT=NEXT),               
  IFTHEN=(WHEN=(1,3,CH,EQ,C'AAA',AND,34,4,CH,EQ,C'1231'),     
  OVERLAY=(201:30,4,ZD,ADD,+1,EDIT=(TTTT),C'001',             
           030:201,7,Y4T,TOGREG=Y4T),HIT=NEXT),               
                                                               
  IFTHEN=(WHEN=(01,3,CH,EQ,C'AAA',AND,44,4,CH,NE,C'1231',AND,   
                40,8,CH,NE,C'00000000'),                       
  OVERLAY=(211:40,8,Y4T,TOJUL=Y4T,                             
           215:215,3,ZD,ADD,+1,EDIT=(TTT),                     
           040:211,7,Y4T,TOGREG=Y4T),HIT=NEXT),               
  IFTHEN=(WHEN=(1,3,CH,EQ,C'AAA',AND,44,4,CH,EQ,C'1231'),     
  OVERLAY=(211:40,4,ZD,ADD,+1,EDIT=(TTTT),C'001',             
           040:211,7,Y4T,TOGREG=Y4T))                         
//*
Back to top
View user's profile Send private message
siva102

New User


Joined: 28 Nov 2007
Posts: 64
Location: Chennai

PostPosted: Sun Aug 08, 2010 8:13 am    Post subject:
Reply with quote

Hi Kolusu,

Once again thank you so much for the help and for the explanation of the code.

I ll surely take care of this concept from next time onwards.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Nov 03, 2010 12:43 am    Post subject:
Reply with quote

siva102 wrote:
The input file is a FB of lrcl = 320. And we need to change the date field in two places. The conditions are like below,

If 1 to 3 character = AAA then one date field starts from 40th position and the second date starts from 48th position and these dates need to be added one day.



siva102,

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 add/subtract days, months or years to a given date like shown below.

Code:

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SORTIN   DD *                                                 
21211S ASD JJSA                                                 
SDH2892 J23BJ24  SDFSDFS GDY5R 567568  6786  697897 69           
234KNS903 LKSDFJK33 JJ343434                                     
AAA0 SDFSDF DSFATM ASJAHI23DGASJHURJOTK2010063020100805DFSSFSDF 
JH788823 HG21881 8811N 81                                       
1000 SDFSDF DSFASJAHI23DG20DFSSFSDF                             
AAA0 SDFSDF DSFATM ASJAHI23DGAHITHUGJNH2009123120100607DFSSFSDF 
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                 
  SORT FIELDS=COPY                                               
  INREC IFOUTLEN=320,                                           
  IFTHEN=(WHEN=(1,3,CH,EQ,C'AAA'),                               
  OVERLAY=(40:40,8,Y4T,ADDDAYS,+1,TOGREG=Y4T,                   
           48:48,8,Y4T,ADDDAYS,+1,TOGREG=Y4T))                   
//*


The output from the above code is

Code:

21211S ASD JJSA                                                 
SDH2892 J23BJ24  SDFSDFS GDY5R 567568  6786  697897 69         
234KNS903 LKSDFJK33 JJ343434                                   
AAA0 SDFSDF DSFATM ASJAHI23DGASJHURJOTK2010070120100806DFSSFSDF
JH788823 HG21881 8811N 81                                       
1000 SDFSDF DSFASJAHI23DG20DFSSFSDF                             
AAA0 SDFSDF DSFATM ASJAHI23DGAHITHUGJNH2010010120100608DFSSFSDF




siva102 wrote:

For FILE -2

The input file is a FB of lrcl = 190. And we need to change the date field in three places. The conditions are like below,

If 1 to 3 character = AAA then one date field starts from 20th position and the second date starts from 30th position and the third one from 40th pos and to those we need to add one day.

We have one more condition here is from these three dates sometimes we can have 00000000 instead of any date. And we dont need to change anything in that case.



00000000 is considered as a special date and date arithmetic functions do not add perform arithmetic on them and leave them as is.

Code:

//STEP0200 EXEC PGM=SORT                                 
//SYSOUT   DD SYSOUT=*                                   
//SORTIN   DD *                                         
21211S ASD JJSA                                         
SDH2892 J23BJ24  SDFSDFS GDY5R 567568  6786  697897 69   
234KNS903 LKSDFJK33 JJ343434                             
AAA0 SDFSDF DSFABCA20090304JH20100103RS00000000JH       
1000 SDFSDF DSFASJAHI23DG20DFSSFSDF                     
----+----1----+----2----+----3----+----4----+----5----+--
AAA0 SDFSDF DSFABCA20090506JH20100103RS20100908JH       
//SORTOUT  DD SYSOUT=*                                   
//SYSIN    DD *                                         
  SORT FIELDS=COPY                                       
  INREC IFOUTLEN=190,                                   
  IFTHEN=(WHEN=(1,3,CH,EQ,C'AAA'),                       
  OVERLAY=(20:20,8,Y4T,ADDDAYS,+1,TOGREG=Y4T,           
           30:30,8,Y4T,ADDDAYS,+1,TOGREG=Y4T,           
           40:40,8,Y4T,ADDDAYS,+1,TOGREG=Y4T))           
//*


The output from this job is

Code:

21211S ASD JJSA                                         
SDH2892 J23BJ24  SDFSDFS GDY5R 567568  6786  697897 69   
234KNS903 LKSDFJK33 JJ343434                             
AAA0 SDFSDF DSFABCA20090305JH20100104RS00000000JH       
1000 SDFSDF DSFASJAHI23DG20DFSSFSDF                     
AAA0 SDFSDF DSFABCA20090507JH20100104RS20100909JH       



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?rs=114&uid=isg3T7000242
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1754
Location: Bloomington, IL

PostPosted: Wed Nov 03, 2010 5:07 pm    Post subject: Re: Reply to: Adding one day to a date field YYYYMMDD
Reply with quote

Skolusu wrote:
The logic is quite simple. In order to add a day to existing date

1.we need to convert the Gregorian date (CCYYMMDD) into Julian date(CCYYDDD) ( ddd= day of year) . This is done by the function TOJUL

2. Add +1 to the DDD portion

3. Now you have to perform the reverse of step 1 which is converting the Julian date to Gregorian date. This is done by the function TOGREG.

However there is a loophole with this approach when the date is December 31st. adding 1 day would make it invalid day of the year. so in that case we increment the year by 1 and set the day of the year to 1 and perform step 3.

Are there any plans in the works to have DFSORT use Lilian day numbers rather than pseudo-Julian dates?
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Nov 03, 2010 10:15 pm    Post subject: Re: Reply to: Adding one day to a date field YYYYMMDD
Reply with quote

Akatsukami wrote:

Are there any plans in the works to have DFSORT use Lilian day numbers rather than pseudo-Julian dates?


NO. I wonder why you refer the Julian date as psuedo dates. The Lilian day numbers can be calculated using DFSORT functions. 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).

Lilian day number 1 started at midnight on the first day of the Gregorian calendar, that is, 15 October 1582. So if you want to convert any date to Lilian day format , all you need to do is subtract that date from 14 October 1582.

ex:

Code:

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SORTIN   DD *                                                 
15821015                                                         
19880516                                                         
20101103                                                         
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                 
  SORT FIELDS=COPY                                               
  INREC IFOUTLEN=80,IFTHEN=(WHEN=INIT,OVERLAY=(81:C'15821014')),
  IFTHEN=(WHEN=INIT,OVERLAY=(15:1,8,Y4T,DATEDIFF,81,8,Y4T))     
//*


The result is
Code:

15821015      +0000001
19880516      +0148138
20101103      +0156344                                                             
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1754
Location: Bloomington, IL

PostPosted: Wed Nov 03, 2010 10:38 pm    Post subject: Re: Reply to: Adding one day to a date field YYYYMMDD
Reply with quote

Skolusu wrote:
Akatsukami wrote:

Are there any plans in the works to have DFSORT use Lilian day numbers rather than pseudo-Julian dates?


NO. I wonder why you refer the Julian date as psuedo dates.

Not pseudo dates; pseudo-Julian dates. An actual Julian date would be a date in the (possibly proleptic) Julian calendar, which I am tolerably certain is not available on z/OS (although it could be calculated, of course).

As for pseudo-Julianism: I suspect, although I haven't researched the matter, that the term began when some half-educated programmers confused ordinal day number (number of days since 12/31 of last year) with Julian day number (number of days since 1/1/4713 BCE 12:00:00 UTC, the last time that the Roman indiction, Metonic cycle, and solar cycle all began together) and called a date in CCYYDDD format a "Julian date". Outside of earth science and IT, that's considered incorrect terminology...and you know how important terminology is icon_wink.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts Adding big TEXT lines to each record ... bshkris SYNCSORT 4 Sat May 06, 2017 1:40 am
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts Alter &DATENS field in HEADER1 Angad DFSORT/ICETOOL 4 Mon Apr 24, 2017 11:49 am
No new posts LISTIDR compiled date/time jerryte IBM Tools 3 Thu Apr 20, 2017 7:37 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us