MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Breaking Sequence numbers based on a field

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Mon Jul 26, 2004 8:01 am    Post subject: Breaking Sequence numbers based on a field Reply with quote

Hi,

I have a file with data as shown below (LRECL=80,RECFM=FB). I need to add sequence numbers at the end that should be reset to 1 for every key split.

Code:

AAA
AAA
AAA
BBB
BBB
CCC
DDD
DDD
DDD
DDD


the output file should look like this
Code:

Output:
AAA   1
AAA   2
AAA   3
BBB   1
BBB   2
CCC  1
DDD  1
DDD  2
DDD  3
DDD  4


Can this be done using SORT ?

Thanks a lot.
Phantom
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12377
Topics: 75
Location: San Jose

PostPosted: Mon Jul 26, 2004 8:31 am    Post subject: Reply with quote

Phantom,

Adding a seqnum to records whenever a key changes is POSSIBLE with a trick using SPLICE. However my shop has syncsort version which does not support SPLICE. so may be frank can come up with a solution for this.

I don't think there is a way to add a seqnum whenever a key changes with traditional features available in sort. One way to do is to via exit routine. If you have Eztrieve at your shop then the folllowing will give you the results.

Code:

//STEP0200 EXEC PGM=EZTPA00                     
//STEPLIB  DD DSN=EASYTREV.LOADLIB,   
//            DISP=SHR                         
//SYSPRINT DD SYSOUT=*                         
//SYSOUT   DD SYSOUT=*                         
//SYSSNAP  DD SYSOUT=*                         
//SYSUDUMP DD SYSOUT=*                         
//INFILE   DD *                                 
AAA                                             
AAA                                             
AAA                                             
BBB                                             
BBB                                             
CCC                                             
DDD                                             
DDD                                             
DDD                                             
DDD                                             
//OUTFILE  DD SYSOUT=*,LRECL=82                 
//SYSIN    DD *                                 
                                               
FILE INFILE                                     
     IN-KEY        1  03 A                     
                                               
FILE SORTFILE FB(80 0) VIRTUAL                 
     SORT-KEY      1  03 A                     
                                               
FILE OUTFILE FB(0 0)                           
     OUT-KEY       1  03  A                     
     OUT-SEQ       05 02  N                     
                                               
PREVIOUS-KEY  W 03 A VALUE ' '                 
NEXT-SEQUENCE W 02 N VALUE 0                   
                                               
SORT INFILE TO SORTFILE USING (IN-KEY)         
                           
JOB INPUT SORTFILE                           
                                             
  IF SORT-KEY EQ PREVIOUS-KEY               
     NEXT-SEQUENCE = NEXT-SEQUENCE + 1       
  ELSE                                       
     NEXT-SEQUENCE = 1                       
     PREVIOUS-KEY = SORT-KEY                 
  END-IF                                     
                                             
  OUT-KEY  = SORT-KEY                       
  OUT-SEQ  = NEXT-SEQUENCE                   
  PUT OUTFILE                               
/*                         


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Mon Jul 26, 2004 9:22 am    Post subject: Reply with quote

Thanks a lot Kolusu,

Unfortunately we also have SYNCSORT here... Crying or Very sad

Thanks for the suggestion kolusu.
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Thu Jul 29, 2004 1:50 am    Post subject: Reply with quote

Frank,

Though we donot have DFSORT at my shop, I still would like to learn how to achieve the above mentioned thro' DFSORT. Could you please provide me the solution.

Thanks for your help and guidance,
Phantom
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12377
Topics: 75
Location: San Jose

PostPosted: Thu Jul 29, 2004 4:35 am    Post subject: Reply with quote

Phantom,

The following DFSORT/ICETOOL JCL will give you the desired results. A brief explanation of the job.

The first sort operator sorts the file on the key which is in the first 3 bytes. We add a seqnum to all the records using OUTREC FIELDS. Now using sections and MIN on the trailer3 parm we get the lowest of the seqnum for each equal group key. We also create another file with all the records.

The SPLICE operator then takes in these 2 files concatenated and populates the key break seqnum for all the records. The formula is to get the key break seqnum is Seqnum - min + 1

If you want to see how the job works, create t1 and t2 as permanent datasets instead of temp datasets and see the contents of them. you need to check the byte 1,3 and 81 thru 90. Then try to apply the formula for the records in t2

Code:

//STEP0100 EXEC PGM=ICETOOL   
//TOOLMSG  DD SYSOUT=*       
//DFSMSG   DD SYSOUT=*       
//IN       DD *               
AAA                           
AAA                           
AAA                           
BBB                           
BBB                           
CCC                           
DDD                           
DDD                           
DDD                           
DDD                           
//TOOLIN   DD *                                                     
  SORT   FROM(IN)  USING(CTL1)                                       
  SPLICE FROM(CON) TO(OUT) ON(1,3,CH) WITH(1,85) WITHALL USING(CTL2)
//*
//T1       DD DSN=&T1,DISP=(,PASS),UNIT=SYSDA,SPACE=(CYL,(X,Y),RLSE)
//T2       DD DSN=&T2,DISP=(,PASS),UNIT=SYSDA,SPACE=(CYL,(X,Y),RLSE)
//CON      DD DSN=&T1,DISP=OLD,VOL=REF=*.T1
//         DD DSN=&T2,DISP=OLD,VOL=REF=*.T2
//OUT      DD SYSOUT=*
//CTL1CNTL DD *                                           
  SORT FIELDS=(1,3,CH,A)                                   
  OUTREC FIELDS=(1,80,SEQNUM,5,ZD,5X)       
  OUTFIL FNAMES=T1,NODETAIL,REMOVECC,                     
  SECTIONS=(1,3,TRAILER3=(1,85,MIN=(81,5,ZD,M11,LENGTH=5)))
  OUTFIL FNAMES=T2                                       
//CTL2CNTL DD *   
  OUTFIL FNAMES=OUT,                                       
  OUTREC=(1,3,C'-',                               
          ((81,5,ZD,SUB,86,5,ZD),ADD,+1),EDIT=(TTTTT),80:X)
/*                                                       


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Sun Aug 22, 2004 4:02 am    Post subject: Reply with quote

Kolusu,

One more shocking news.....I was just informed that Eazytrieve is going to be phased out from our shop. The only answer I get is COST CUTTING !!!!!!!!! Mad

I was told that Eazytrive is going to be replaced by SAS. Similarly lots of utilties are being replaced...I don't want to use any of these third party tools here...b'cas they might replace them any moment...

Could you please provide me a ASSEMBLER equivalent (Using SORT E35 EXIT)of your Eazytrieve code.

Note: I never used ASSEMBLER before. I just downloaded some manuals on HLASM.

Thanks a ton in advance for all the help,
Back to top
View user's profile Send private message
MikeBaker
Beginner


Joined: 04 May 2004
Posts: 96
Topics: 9

PostPosted: Mon Aug 23, 2004 6:45 am    Post subject: Reply with quote

I would not want to be responsible for supporting a production assembler program (esp. an internal sort) without being adept at Assembler. From what you have described, there seems to be no good reason for an Assembler module.

Why not do it the easy way instead?
Step 1: Have a SORT step.
Step 2: Write a little program in any language to do what you want.
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Mon Aug 23, 2004 11:49 am    Post subject: Reply with quote

I understand Mikebaker,

But the input file will be dynamic. Meaning the LRECL varies from time to time. though I can allocate a file dynamically using COBOL the LRECL should be fixed.
I'm also looking a way to acheive this using C in mainframes. Not sure how successful I would be.

That is the reason I tried to go for Assembler.

Thanks a lot,
Phantom
Back to top
View user's profile Send private message
MikeBaker
Beginner


Joined: 04 May 2004
Posts: 96
Topics: 9

PostPosted: Mon Aug 23, 2004 6:08 pm    Post subject: Reply with quote

Hi Phantom,

Ok, that is a good reason to use Assembler. However, to do this in Assembler dynamically is also non-standard Assembler programming. I have seen examples of this, and it is a bit fiddly.

You can either use the SYS1.MACLIB(DCBD) member, and then code the appropriate control block inquiry code in your program, or I think (without referencing the manual), the RDJFCB macro might be able to do the same.

I would definitely hunt for an easier solution, and only use Assember as a last resort. It could be real nasty if you got to be reliant on this in prod, and it failed.

Cheers.
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Thu Jun 30, 2005 10:42 am    Post subject: Reply with quote

You can do this kind of thing much more easily and efficiently using the new RESTART parameter of DFSORT available with z/OS V1R5 PTF UQ95214 or DFSORT R14 PTF UQ95213 (Dec, 2004). Here's the job:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
AAA
AAA
AAA
BBB
BBB
CCC
DDD
DDD
DDD
DDD
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  OPTION COPY
  INREC OVERLAY=(6:SEQNUM,1,ZD,RESTART=(1,3))
/*

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group