View previous topic :: View next topic
|
Author |
Message |
Mikel Terracina
New User
Joined: 02 Apr 2012 Posts: 11 Location: USA
|
|
|
|
Hi,
Is there a way, using SYNCSORT, to add sequence numbers to a file, but only increment when a key field changes?
For example, I have this file:
Code: |
AAAAA A1
AAAAA A1
BBBBB B1
BBBBB B1
CCCCC C1
CCCCC C1
AAAAA A2
AAAAA A2
AAAAA A2
BBBBB B2
BBBBB B2
CCCCC C2
CCCCC C2
AAAAA A3
... |
I'd like to add sequence numbers as such:
Code: |
AAAAA A1 1
AAAAA A1 1
BBBBB B1 2
BBBBB B1 2
CCCCC C1 3
CCCCC C1 3
AAAAA A2 4
AAAAA A2 4
AAAAA A2 4
BBBBB B2 5
BBBBB B2 5
CCCCC C2 6
CCCCC C2 6
AAAAA A3 7
... |
Thanks in advance for your help,
Mike |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, have a look at IFTHEN=(WHEN=GROUP with PUSH and ID. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10886 Location: italy
|
|
|
|
Code: |
****** ***************************** Top of Data ******************************
- - - - - - - - - - - - - - - - - - - 3 Line(s) not Displayed
000004 //S1 EXEC PGM=SORT
000005 //SYSPRINT DD SYSOUT=*
000006 //SYSOUT DD SYSOUT=*
000007 //SORTIN DD *
000008 AAA 111
000009 AAA 111
000010 BBB 211
000011 AAA 112
000012 AAA 112
000013 AAA 112
000014 BBB 212
000015 BBB 212
000016 AAA 113
000017 AAA 113
000018 AAA 113
000019 AAA 113
000020 BBB 213
000021 BBB 213
000022 BBB 213
000023 //SORTOUT DD SYSOUT=*,
000024 // DCB=(RECFM=FB,LRECL=80)
000025 SORT FIELDS=COPY
000026 INREC IFOUTLEN=80,
000027 IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,3))),
000028 IFTHEN=(WHEN=GROUP,BEGIN(81,8,ZD,EQ,1),PUSH=(9:ID=3))
000029 OUTFIL BUILD=(1,80)
000030 //*
****** **************************** Bottom of Data **************************** |
the result
Code: |
********************************* TOP OF DATA **********************************
AAA 111 001
AAA 111 001
BBB 211 002
AAA 112 003
AAA 112 003
AAA 112 003
BBB 212 004
BBB 212 004
AAA 113 005
AAA 113 005
AAA 113 005
AAA 113 005
BBB 213 006
BBB 213 006
BBB 213 006
******************************** BOTTOM OF DATA ******************************** |
should be simple to modify according to Your need |
|
Back to top |
|
|
Mikel Terracina
New User
Joined: 02 Apr 2012 Posts: 11 Location: USA
|
|
|
|
Thanks Enrico! It works beautifully |
|
Back to top |
|
|
Mikel Terracina
New User
Joined: 02 Apr 2012 Posts: 11 Location: USA
|
|
|
|
Just out of curiosity, would there be a way to start the sequencing at a number you specify, rather than 1? According to my syncsort manual, it looks like PUSH only starts at 1. Just curious...
Thanks,
Mike |
|
Back to top |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
you can try something ilke this where the ID starts at 2
Code: |
SORT FIELDS=COPY
INREC IFOUTLEN=80,
IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,3))),
IFTHEN=(WHEN=GROUP,BEGIN=(81,8,ZD,EQ,1),PUSH=(9:ID=3)),
IFTHEN=(WHEN=INIT,OVERLAY=(9:9,3,ZD,ADD,+1,EDIT=(TTT)))
|
Gerry |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10886 Location: italy
|
|
|
|
as far as IBM DFSORT is concerned the CLAUSE
Code: |
...SEQNUM,...,START=<start>,INCR=<incr>,... |
is supported
should be the same for SYNCSORT |
|
Back to top |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi Enrico,
I took the O/P as wanting the ID as starting from a different number and not the SEQNUM.
Gerry |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10886 Location: italy
|
|
|
|
Quote: |
would there be a way to start the sequencing at a number you specify |
I stopped reading after the word sequencing |
|
Back to top |
|
|
Mikel Terracina
New User
Joined: 02 Apr 2012 Posts: 11 Location: USA
|
|
|
|
I tried that out and it works great!
Thanks Gerry! |
|
Back to top |
|
|
|