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

Syncsort SEQNUM question


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Mikel Terracina

New User


Joined: 02 Apr 2012
Posts: 11
Location: USA

PostPosted: Fri Jan 04, 2013 5:42 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Jan 04, 2013 6:01 am
Reply with quote

Yes, have a look at IFTHEN=(WHEN=GROUP with PUSH and ID.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Fri Jan 04, 2013 6:11 am
Reply with quote

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
View user's profile Send private message
Mikel Terracina

New User


Joined: 02 Apr 2012
Posts: 11
Location: USA

PostPosted: Fri Jan 04, 2013 10:56 pm
Reply with quote

Thanks Enrico! It works beautifully icon_biggrin.gif
Back to top
View user's profile Send private message
Mikel Terracina

New User


Joined: 02 Apr 2012
Posts: 11
Location: USA

PostPosted: Sat Jan 05, 2013 12:18 am
Reply with quote

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
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Sat Jan 05, 2013 1:57 am
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Sat Jan 05, 2013 2:01 am
Reply with quote

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
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Sat Jan 05, 2013 2:43 am
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Sat Jan 05, 2013 2:58 am
Reply with quote

icon_redface.gif
Quote:
would there be a way to start the sequencing at a number you specify

I stopped reading after the word sequencing icon_wink.gif
Back to top
View user's profile Send private message
Mikel Terracina

New User


Joined: 02 Apr 2012
Posts: 11
Location: USA

PostPosted: Sat Jan 05, 2013 3:44 am
Reply with quote

I tried that out and it works great! icon_biggrin.gif
Thanks Gerry!
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 -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Question for file manager IBM Tools 7
No new posts question for Pedro TSO/ISPF 2
No new posts Count Records with a crietaria in a f... DFSORT/ICETOOL 5
No new posts question on Outrec and sort #Digvijay DFSORT/ICETOOL 20
Search our Forums:

Back to Top