|
View previous topic :: View next topic
|
| Author |
Message |
matthewchin
New User
Joined: 23 Dec 2021 Posts: 3 Location: HK
|
|
|
|
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 |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3112 Location: NYC,USA
|
|
|
|
| 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 |
|
 |
matthewchin
New User
Joined: 23 Dec 2021 Posts: 3 Location: HK
|
|
|
|
| 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 |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2290 Location: USA
|
|
|
|
| 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 |
|
 |
matthewchin
New User
Joined: 23 Dec 2021 Posts: 3 Location: HK
|
|
|
|
| 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 |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1448 Location: Bamberg, Germany
|
|
|
|
| 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 |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2290 Location: USA
|
|
|
|
| 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 |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|