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

Repeating sequence numbers for a particular no of records


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

New User


Joined: 06 Jun 2013
Posts: 25
Location: India

PostPosted: Thu Sep 18, 2014 7:50 pm
Reply with quote

Hi,
I need the sequence number repeated for every 'n' number of records. These 'n' number of records will have the same key.
Not always will the input contain 'n' number of records for a group.
In this case, is it possible to create dummy records or blank records with sequence numbers still, if there are records less than 'n'?

Like,
Input:
Code:
AAA
AAA
AAA
BBB
BBB
CCC
CCC
CCC

Say, Positions 1-3 will have the key. I need to repeat sequence number for every 3 records (not more than 3 records would have the same key),

Output:
Code:
AAA01
AAA02
AAA03
BBB01
BBB02
   03
CCC01
CCC02
   03


Kindly help.

Code'd
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: Thu Sep 18, 2014 9:55 pm
Reply with quote

Have a look at this one and apply it to your requirement.

You will use it for "change of key".

Add the sequence number (with KEYBEGIN on WHEN=GROUP if SyncSORT has that, else with RESTART on SEQNUM).

When the key break occurs, look at your current sequence value. If 1, you need to add two records. If 2, you need to add one record.

Since you need to add records, you will do this in OUTFIL with the slash operator (/).
Back to top
View user's profile Send private message
Shrinika Rajendran

New User


Joined: 06 Jun 2013
Posts: 25
Location: India

PostPosted: Wed Sep 24, 2014 12:42 pm
Reply with quote

Thanks much Bill.

1. Used JOINKEYS with the same dataset for both files
2. Applying seq num for both the files, with seq num starting from 1 for one dataset and 0 for another.
3. Reapplied sequence number with restart.
4. Checked the reapplied new sequence number at key change.
6. If its not the restart value, added the records using OUTFIL and '/' to create empty records.

Thanks again for the help. The link you provided and the hyperlinks that it has are of much use!
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: Wed Sep 24, 2014 1:55 pm
Reply with quote

No problem. Good work. Can you post the code, as it may help others in the future and I don't think we have anything here of that type of example.
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Wed Sep 24, 2014 6:20 pm
Reply with quote

Today I was working on something similar, but not exactly like this. I have to add the sequence no and total count of each type of record. Posting my code here. Hope this helps.

Input:
Code:
ABC                   
ABC                   
ABC                   
PQR                   
XYZ                   
XYZ


Output
Code:
ABC                 01        03
ABC                 02        03
ABC                 03        03
PQR                 01        01
XYZ                 01        02
XYZ                 02        02


SORT Card: ( I have Syncsort V1.4.1.0R)
Code:
  INREC  IFTHEN=(WHEN=INIT,                             
                 OVERLAY=(31:SEQNUM,2,ZD,RESTART=(1,3)))
  SORT   FIELDS=(1,3,CH,A,31,2,CH,D)                     
  OUTREC IFOUTLEN=32,                                   
         IFTHEN=(WHEN=INIT,                             
                 OVERLAY=(21:SEQNUM,2,ZD,RESTART=(1,3), 
                          33:SEQNUM,2,ZD,RESTART=(1,3))),
         IFTHEN=(WHEN=GROUP,                             
                 BEGIN=(33,2,ZD,EQ,1),PUSH=(31:31,2))   
Back to top
View user's profile Send private message
Shrinika Rajendran

New User


Joined: 06 Jun 2013
Posts: 25
Location: India

PostPosted: Thu Sep 25, 2014 3:11 pm
Reply with quote

Sure. Below are the steps.

Step:1: Input
Code:
//SORTJNF1 DD  *   
AAA                 
AAA                 
AAA                 
BBB                 
BBB                 
CCC                 
/*                 
//SORTJNF2 DD  *   
AAA                 
AAA                 
AAA                 
BBB                 
BBB                 
CCC                 
/*                 


Sort statements:
Code:
//SYSIN    DD *                                   
  JOINKEYS FILES=F1,FIELDS=(4,1,A),SORTED,NOSEQCK 
  JOINKEYS FILES=F2,FIELDS=(4,1,A),SORTED,NOSEQCK 
  REFORMAT FIELDS=(F1:1,3,F2:1,3,?)               
  JOIN UNPAIRED,F1                                 
  SORT FIELDS=COPY                                 
/*                                                 
//JNF1CNTL DD *                                   
  OPTION COPY                                     
  INREC OVERLAY=(4:SEQNUM,1,ZD)                   
/*                                                 
//JNF2CNTL DD *                                   
  OPTION COPY                                     
  INREC OVERLAY=(4:SEQNUM,1,ZD,START=0)           
/*                                                 
//*                                               


Step 2:
Code:
//SYSIN    DD *                                                   
   SORT FIELDS=COPY                                               
   OUTREC BUILD=(1,3,X,4,3,X,7,1,X,SEQNUM,1,ZD,RESTART=(1,3),100:X)
/*                                                                 
//*                                                               


Step 3:
Code:
 SORT FIELDS=COPY                                           
OUTFIL IFTHEN=(WHEN=((1,3,CH,NE,5,3,CH,OR,9,1,ZD,EQ,1),AND,
              (11,1,ZD,EQ,3)),                             
     BUILD=(1,3,X,11,1)),                                   
IFTHEN=(WHEN=((1,3,CH,NE,5,3,CH,OR,9,1,ZD,EQ,1),AND,       
              (11,1,ZD,EQ,2)),                             
     BUILD=(1,3,X,11,1,/,                                   
            1:3X,X,C'3')),                                 
IFTHEN=(WHEN=((1,3,CH,NE,5,3,CH,OR,9,1,ZD,EQ,1),AND,       
              (11,1,ZD,EQ,1)),                             
     BUILD=(1,3,X,11,1,/,                                   
            1:3X,X,C'2',/,                                 
            1:3X,X,C'3')),                                 
IFTHEN=(WHEN=NONE,                                         
     BUILD=(1,3,X,11,1))                                   


Final Output:
Code:
AAA 1
AAA 2
AAA 3
BBB 1
BBB 2
    3
CCC 1
    2
    3
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: Thu Sep 25, 2014 3:55 pm
Reply with quote

Thanks.

I can't see any reason to do it in three steps. Here is your code in one step:

Code:
//SYSIN    DD *                                   
  JOINKEYS FILES=F1,FIELDS=(4,1,A),SORTED,NOSEQCK
  JOINKEYS FILES=F2,FIELDS=(4,1,A),SORTED,NOSEQCK
  REFORMAT FIELDS=(F1:1,3,F2:1,3,?)               
  JOIN UNPAIRED,F1                                 
  SORT FIELDS=COPY               
  OUTREC BUILD=(1,3,X,4,3,X,7,1,X,SEQNUM,1,ZD,RESTART=(1,3),100:X)
 
  OUTFIL IFTHEN=(WHEN=((1,3,CH,NE,5,3,CH,OR,9,1,ZD,EQ,1),AND,
              (11,1,ZD,EQ,3)),                             
     BUILD=(1,3,X,11,1)),                                   
  IFTHEN=(WHEN=((1,3,CH,NE,5,3,CH,OR,9,1,ZD,EQ,1),AND,       
              (11,1,ZD,EQ,2)),                             
     BUILD=(1,3,X,11,1,/,                                   
            1:3X,X,C'3')),                                 
  IFTHEN=(WHEN=((1,3,CH,NE,5,3,CH,OR,9,1,ZD,EQ,1),AND,       
              (11,1,ZD,EQ,1)),                             
     BUILD=(1,3,X,11,1,/,                                   
            1:3X,X,C'2',/,                                 
            1:3X,X,C'3')),                                 
  IFTHEN=(WHEN=NONE,                                         
     BUILD=(1,3,X,11,1))                                                     
//JNF1CNTL DD *                                   
  OPTION COPY                                     
  INREC OVERLAY=(4:SEQNUM,1,ZD)                   
//JNF2CNTL DD *                                   
  OPTION COPY                                     
  INREC OVERLAY=(4:SEQNUM,1,ZD,START=0)     


You can use INREC instead of OUTREC. I see no reason for the 100:X, since you later BUILD only 5-byte records. There's no point adding data that you are not going to use.

You don't really need to include the blanks (Xs) on your first BUILD either. They can be useful to "see" the data more easily as you develop a solution, but can come out of the final version. To take them out, you need to adjust the later positions. You can "automate" that, and make your control cards more "self-documenting" by using symbols/SYMNAMES.

I like to make things easier to read, so here's part of a rearrangement:

Code:
  OUTFIL IFTHEN=(WHEN=((1,3,CH,NE,5,3,CH,
                       OR,
                        9,1,ZD,EQ,1),
                      AND,
                       (11,1,ZD,EQ,3)),                             
                     BUILD=(1,3,X,11,1)),     


As well as being easier to read, it is easier to maintain. Note some of the formatting that mistah kurtz applied as well (I'd go further, but that's me :-) ). The way you've coded the BUILD with the slash operator (/) is good (though again I'd go further and put the "/," on its own line.

You got the solution, it is then just a question of some consolidation and tidying, and applying what you've learned from the whole process in the future.
Back to top
View user's profile Send private message
Shrinika Rajendran

New User


Joined: 06 Jun 2013
Posts: 25
Location: India

PostPosted: Thu Sep 25, 2014 5:53 pm
Reply with quote

All the points about formatting and putting everything in a single step, noted icon_smile.gif
Thanks Bill!
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Generate random number from range of ... COBOL Programming 3
No new posts Join multiple records using splice DFSORT/ICETOOL 5
Search our Forums:

Back to Top