Page 1 of 1

reseq to generate numbers with defined keys

PostPosted: Wed Jan 21, 2009 5:57 am
by defnk
Hi guys,

First post here.

Hope someone can help with this SORT related issue.

I have a file that has (amongst other fields) columns A through E.
What I'm trying to do is to generate 2 sequence numbers (in cols 98 and 100 binary format) based on combinations of columns A through F, in a new column of the same file.


Currently using this JCL/sort (unsuccessfully).

//SORT01   EXEC PGM=SORT,REGION=4M                               
//SORTIN   DD  DSN=*.UNLOAD01.SYSREC00,DISP=SHR                   
//SORTOUT  DD  DSN=*.DELETE.CNVPOLS,                             
//             DISP=(NEW,CATLG,DELETE),                           
//             UNIT=SYSDA,SPACE=(TRK,(150,150),RLSE)             
//SYSIN    DD  *                                                 
   SORT FIELDS=(1,2,BI,A,                      A           
                3,3,CH,A,                      B           
                6,4,BI,A,                      C             
                10,2,BI,A,                     D             
                12,2,BI,A,                     E         
                14,4,BI,A)                     F             
  OUTREC  OVERLAY=(98:SEQNUM,2,BI,RESTART=(1,9),                 
                    100:SEQNUM,2,BI,RESTART=(1,11))               
/*                                                               
//SYSOUT   DD  SYSOUT=*                                           
//SRTMSG   DD  SYSOUT=*                                           


The method of generating the numbers is proving the issue.
The first generated number in column 98 should start at 1 and increment for each record where : A, B, C, E and F are the same and D is different.
The second generated number in column 100 should start at 1 and increment for each record where: A, B, C, D and F are the same and E is different.

So here is the input and expected generated output to make it clearer :

      A     B      C        D         E        F          GEN_X (98)  GEN_Y (100)
---------+---------+---------+---------+---------+---------+---------+------
      1     A    38551       1        1    6560           1             1
      1     A    38551       1        2    6560           1             2

      1     A    51201       2        1    7373           1             1
      1     A    51201       3        1    7373           2             1

      1     A    59551       1        1    5856           1             1
      1     A    59551       1        2    5856           1             2

      1     A    62651       1        1    5166           1             0
      1     A    62651       2        1    5166           2             0

      1     A    63041       1        1    5200           1             0
      1     A    63041       1        2    5200           2             0

      1     A    63201       2        1    7300           1             0

      1     A    78551       1        1    3856           1             0
      1     A    78551       1        2    3856           2             0
      1     A    78551       1        3    3856           3             0


Possibly the sort may need to be done in two stages?

Thanks for any assistance - sorry about the long post!

Re: reseq to generate numbers with defined keys

PostPosted: Wed Jan 21, 2009 10:08 pm
by skolusu
The first generated number in column 98 should start at 1 and increment for each record where : A, B, C, E and F are the same and D is different.
The second generated number in column 100 should start at 1 and increment for each record where: A, B, C, D and F are the same and E is different.


Your output does not match the rules. Your output has zero as seqnum at 100 for the last 8 keys. Shouldn't you increment it? Can you explain as to why you have zero instead of seqnum?

Re: reseq to generate numbers with defined keys

PostPosted: Thu Jan 22, 2009 4:15 am
by defnk
Yes you are right - the output is wrong!
Corrected here...


      A     B      C        D         E        F          GEN_X (98)  GEN_Y (100)
---------+---------+---------+---------+---------+---------+---------+------
      1     A    38551       1        1    6560           1             1
      1     A    38551       1        2    6560           1             2

      1     A    51201       2        1    7373           1             1
      1     A    51201       3        1    7373           2             1

      1     A    59551       1        1    5856           1             1
      1     A    59551       1        2    5856           1             2

      1     A    62651       1        1    5166           1             1
      1     A    62651       2        1    5166           2             1

      1     A    63041       1        1    5200           1             1
      1     A    63041       1        2    5200           1             2

      1     A    63201       2        1    7300           1             1

      1     A    78551       1        1    3856           1             1
      1     A    78551       1        2    3856           1             2
      1     A    78551       1        3    3856           1             3


Possibly the sort may need to be done in two stages?

Thanks for any assistance - sorry about the long post![/quote]

Re: reseq to generate numbers with defined keys

PostPosted: Thu Jan 22, 2009 7:22 am
by skolusu
defnk,

The following JCL will give you the desired results. I assumed that your input LRECL is <=104 and FB recfm.

The trick to get the 2 seqnum's is that

1. We add columns ABCEFD at the end of each record. ie pos 105
2. Sort on the column ABCEFD we added at the end
3. Using OUTREC put ABCF and create the seqnum with restart key as ABCEF and put column D at pos 120 . So pos 120 we have this as key ABCF SEQNUM D
4. Now using another OUTREC create the seqnum with restart key ABCF SEQNUM D at pos 150.
5. Now we have both the seqnum which we want. Using BUILD on OUTFIL we populate pos 98 and 100 and ignore the rest.



//STEP0100 EXEC PGM=SORT           
//SYSOUT   DD SYSOUT=*             
//SORTIN   DD DSN=your input file,
//            DISP=SHR     
//SORTOUT  DD DSN=your output 101 byte file,
//            DISP=SHR
//SYSIN    DD *                     
  OPTION EQUALS                                                 
  INREC OVERLAY=(105:01,9,12,2,14,4,10,2)                       
  SORT FIELDS=(105,17,BI,A)                                     
                                                               
  OUTREC IFTHEN=(WHEN=INIT,                                     
  OVERLAY=(125:105,9,116,4,SEQNUM,2,BI,RESTART=(105,15),120,2)),
  IFTHEN=(WHEN=INIT,OVERLAY=(150:SEQNUM,2,BI,RESTART=(125,17)))
  OUTFIL BUILD=(1,97,138,2,150,2)                               
/*

Re: reseq to generate numbers with defined keys

PostPosted: Thu Jan 22, 2009 8:07 am
by defnk
skolusu wrote:defnk,

The following JCL will give you the desired results. I assumed that your input LRECL is <=104 and FB recfm.


That seems to work just as I need it to skolusu. Thanks for the explanation of your method as well, which is just as important!
Cheers!