IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

sort remove records with date > 7year


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
matthewchin

New User


Joined: 23 Dec 2021
Posts: 3
Location: HK

PostPosted: Thu Dec 23, 2021 5:44 pm
Reply with quote

Hello all,

I have a variable length VSAM (237 to 4087bytes), a date in PD (yyyyddd) on fix position 16 with 4 bytes.

May I know if I can sort out records with this date > (today - 7year) ?
This is for housekeeping purpose (remove records older than 7year) so leap year can be ignored.

I review DATE3P, DATEDIFF, but cannot figure how to specify in INCLUDE COND statement in sort, as it is variable length file, I am not sure how to put e.g. a (date - 7year) field at end of each record, or in another temp file ?

Many thx for help.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2945
Location: NYC,USA

PostPosted: Thu Dec 23, 2021 6:27 pm
Reply with quote

One way, Use INREC OVERLAY to get the final dates ( date- 7 years) and later use that value in OUTFIL INCLUDE to apply filter.
Back to top
View user's profile Send private message
matthewchin

New User


Joined: 23 Dec 2021
Posts: 3
Location: HK

PostPosted: Thu Dec 23, 2021 7:57 pm
Reply with quote

Rohit Umarjikar wrote:
One way, Use INREC OVERLAY to get the final dates ( date- 7 years) and later use that value in OUTFIL INCLUDE to apply filter.


Able to show some lines of code?

I meant records need intact to sort out if within 7 years.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 1614

PostPosted: Thu Dec 23, 2021 11:11 pm
Reply with quote

matthewchin wrote:
Rohit Umarjikar wrote:
One way, Use INREC OVERLAY to get the final dates ( date- 7 years) and later use that value in OUTFIL INCLUDE to apply filter.


Able to show some lines of code?

I meant records need intact to sort out if within 7 years.

When using &DATE3P you must add/subtract years as normal packed decimal (where years shifted 3 digits left, e.g. 7 years = 7000), and then to compare your packed decimal date with the result of decimal addition/subtraction of the current date. Not a big deal...

Without learning insertions the code should be even more simple, and shorter.

This is the learning test sample. I deliberately do not give you a ready-to-use solution, to make you think a little bit before copy-and-paste the code.
Code:
 
//SORT     EXEC PGM=SYNCSORT                         
//SYSOUT   DD  SYSOUT=*                             
//SORTIN   DD  *                                     
2011111                                             
2012111                                             
2013111                                             
2014111                                             
2015111                                             
2016111                                             
2017111                                             
2018111                                               
2019111                                             
2020111                                             
2021111                                             
//*                                                 
//SORTOUT  DD  SYSOUT=*                             
//SORTOUTF DD  DISP=(NEW,KEEP),SPACE=(TRK,(10,10)), 
//             DSN=&SYSUID..SORTOUT                 
//*                                                   
//SYSIN    DD  *                                     
 INREC IFTHEN=(WHEN=INIT,                           
               BUILD=(1,7,X,                         
                    9:1,7,ZD,TO=PDC,LENGTH=4,X,                 
                   14:&DATE3P,X,                               
                   80:X)),                                     
       IFTHEN=(WHEN=INIT,   MINUS 7 YEARS AS PACKED DECIMAL     
               OVERLAY=(19:14,4,PD,ADD,-7000,TO=PD,LENGTH=4))   
 SORT FIELDS=COPY                                               
 OUTREC BUILD=(1,7,X,        DATE CHAR                         
               9,4,X,        DATE PD                           
               14,4,X,       TODAY PD                           
               19,4,X,       TODAY-7YEARS PD                   
               9,4,HEX,X,    DATE PD HEX                       
               14,4,HEX,X,   TODAY PD HEX                       
               19,4,HEX,X,   TODAY-7YEARS HEX                   
            80:X)                                               
 OUTFIL FNAMES=(SORTOUT,SORTOUTF),                             
        IFTHEN=(WHEN=(9,4,PD,LT,19,4,PD),                       
                BUILD=(1,50,                                     
                    60:C'<== BEFORE')),                         
        IFTHEN=(WHEN=NONE,                                     
                BUILD=(1,50,                                   
                    60:C'<== AFTER'))                           
 END                                                           
//* 


The output result with hex format is as follows.
Code:
 
000001 2011111         @    @ 2011111C 2021357C 2014357C          <== BEFORE
       FFFFFFF4211142237421374FFFFFFFC4FFFFFFFC4FFFFFFFC44444444444774CCCDDC
       20111110011C0015C0045C0201111130202135730201435730000000000CEE0256695
----------------------------------------------------------------------------
000002 2012111         @    @ 2012111C 2021357C 2014357C          <== BEFORE
       FFFFFFF4211142237421374FFFFFFFC4FFFFFFFC4FFFFFFFC44444444444774CCCDDC
       20121110021C0015C0045C0201211130202135730201435730000000000CEE0256695
----------------------------------------------------------------------------
000003 2013111         @    @ 2013111C 2021357C 2014357C          <== BEFORE
       FFFFFFF4211142237421374FFFFFFFC4FFFFFFFC4FFFFFFFC44444444444774CCCDDC
       20131110031C0015C0045C0201311130202135730201435730000000000CEE0256695
----------------------------------------------------------------------------
000004 2014111         @    @ 2014111C 2021357C 2014357C          <== BEFORE
       FFFFFFF4211142237421374FFFFFFFC4FFFFFFFC4FFFFFFFC44444444444774CCCDDC
       20141110041C0015C0045C0201411130202135730201435730000000000CEE0256695
----------------------------------------------------------------------------
000005 2015111         @    @ 2015111C 2021357C 2014357C          <== AFTER
       FFFFFFF4211142237421374FFFFFFFC4FFFFFFFC4FFFFFFFC44444444444774CCECD4
       20151110051C0015C0045C0201511130202135730201435730000000000CEE0163590
----------------------------------------------------------------------------
 
Back to top
View user's profile Send private message
matthewchin

New User


Joined: 23 Dec 2021
Posts: 3
Location: HK

PostPosted: Fri Dec 24, 2021 5:07 am
Reply with quote

sergeyken wrote:
matthewchin wrote:
Rohit Umarjikar wrote:
One way, Use INREC OVERLAY to get the final dates ( date- 7 years) and later use that value in OUTFIL INCLUDE to apply filter.


Able to show some lines of code?

I meant records need intact to sort out if within 7 years.

When using &DATE3P you must add/subtract years as normal packed decimal (where years shifted 3 digits left, e.g. 7 years = 7000), and then to compare your packed decimal date with the result of decimal addition/subtraction of the current date. Not a big deal...

Without learning insertions the code should be even more simple, and shorter.

This is the learning test sample. I deliberately do not give you a ready-to-use solution, to make you think a little bit before copy-and-paste the code.
Code:
 
//SORT     EXEC PGM=SYNCSORT                         
//SYSOUT   DD  SYSOUT=*                             
//SORTIN   DD  *                                     
2011111                                             
2012111                                             
2013111                                             
2014111                                             
2015111                                             
2016111                                             
2017111                                             
2018111                                               
2019111                                             
2020111                                             
2021111                                             
//*                                                 
//SORTOUT  DD  SYSOUT=*                             
//SORTOUTF DD  DISP=(NEW,KEEP),SPACE=(TRK,(10,10)), 
//             DSN=&SYSUID..SORTOUT                 
//*                                                   
//SYSIN    DD  *                                     
 INREC IFTHEN=(WHEN=INIT,                           
               BUILD=(1,7,X,                         
                    9:1,7,ZD,TO=PDC,LENGTH=4,X,                 
                   14:&DATE3P,X,                               
                   80:X)),                                     
       IFTHEN=(WHEN=INIT,   MINUS 7 YEARS AS PACKED DECIMAL     
               OVERLAY=(19:14,4,PD,ADD,-7000,TO=PD,LENGTH=4))   
 SORT FIELDS=COPY                                               
 OUTREC BUILD=(1,7,X,        DATE CHAR                         
               9,4,X,        DATE PD                           
               14,4,X,       TODAY PD                           
               19,4,X,       TODAY-7YEARS PD                   
               9,4,HEX,X,    DATE PD HEX                       
               14,4,HEX,X,   TODAY PD HEX                       
               19,4,HEX,X,   TODAY-7YEARS HEX                   
            80:X)                                               
 OUTFIL FNAMES=(SORTOUT,SORTOUTF),                             
        IFTHEN=(WHEN=(9,4,PD,LT,19,4,PD),                       
                BUILD=(1,50,                                     
                    60:C'<== BEFORE')),                         
        IFTHEN=(WHEN=NONE,                                     
                BUILD=(1,50,                                   
                    60:C'<== AFTER'))                           
 END                                                           
//* 


The output result with hex format is as follows.
Code:
 
000001 2011111         @    @ 2011111C 2021357C 2014357C          <== BEFORE
       FFFFFFF4211142237421374FFFFFFFC4FFFFFFFC4FFFFFFFC44444444444774CCCDDC
       20111110011C0015C0045C0201111130202135730201435730000000000CEE0256695
----------------------------------------------------------------------------
000002 2012111         @    @ 2012111C 2021357C 2014357C          <== BEFORE
       FFFFFFF4211142237421374FFFFFFFC4FFFFFFFC4FFFFFFFC44444444444774CCCDDC
       20121110021C0015C0045C0201211130202135730201435730000000000CEE0256695
----------------------------------------------------------------------------
000003 2013111         @    @ 2013111C 2021357C 2014357C          <== BEFORE
       FFFFFFF4211142237421374FFFFFFFC4FFFFFFFC4FFFFFFFC44444444444774CCCDDC
       20131110031C0015C0045C0201311130202135730201435730000000000CEE0256695
----------------------------------------------------------------------------
000004 2014111         @    @ 2014111C 2021357C 2014357C          <== BEFORE
       FFFFFFF4211142237421374FFFFFFFC4FFFFFFFC4FFFFFFFC44444444444774CCCDDC
       20141110041C0015C0045C0201411130202135730201435730000000000CEE0256695
----------------------------------------------------------------------------
000005 2015111         @    @ 2015111C 2021357C 2014357C          <== AFTER
       FFFFFFF4211142237421374FFFFFFFC4FFFFFFFC4FFFFFFFC44444444444774CCECD4
       20151110051C0015C0045C0201511130202135730201435730000000000CEE0163590
----------------------------------------------------------------------------
 


Thx you.
Back to top
View user's profile Send private message
Joerg.Findeisen

Active Member


Joined: 15 Aug 2015
Posts: 907
Location: Bamberg, Germany

PostPosted: Fri Dec 24, 2021 12:03 pm
Reply with quote

Make use of the AGE=YD operator in INREC and later filter by INCLUDE/OMIT. That's the simplest way of doing the task.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 1614

PostPosted: Fri Dec 24, 2021 4:53 pm
Reply with quote

Joerg.Findeisen wrote:
Make use of the AGE=YD operator in INREC and later filter by INCLUDE/OMIT. That's the simplest way of doing the task.

Yes, it simplifies (in DFSORT only) the calculation of date difference value.
But the main incovenience remains the same: the date difference calculated in any manner MUST be (temporary) stored as a separate filed, in order to use it in any condition parameter, like
INCLUDE=(...)...
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts how to keep unpaired records with REPRO. JCL & VSAM 9
No new posts WER999A - UNSUCCESSFUL SORT 8ED U Ab... SYNCSORT 5
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
No new posts Dataset size increase on adding 1 byt... DFSORT/ICETOOL 8
No new posts SORT deletes the SORTOUT file DFSORT/ICETOOL 8
Search our Forums:

Back to Top