View previous topic :: View next topic
|
Author |
Message |
HammerTime
New User
Joined: 26 Sep 2012 Posts: 14 Location: UK
|
|
|
|
Hi all, i'm pulling my hair out with what I can only imagine is a simple bit of logic!
I have an input which looks something like this:
Code: |
1234567890
----------
A CODE1
A CODE4
B CODE3
B CODE9
B CODEX
C CODEEE |
I'm trying to achieve an output where each unique value in pos 1 is replaced with it's own unique sequence number like so:
Code: |
1234567890
----------
01 CODE1
01 CODE4
02 CODE3
02 CODE9
02 CODEX
03 CODEEE |
The reason I'm struggling here is that the values I have provided in my example of A/B/C are very variable inputs (hundreds of possibilities here), so I can't just use a simple replace. What that incoming value is, is not important. What is important is that I have a 'sequence number' (or incremental numerical label starting at 1), which increments whenever the value in pos 1 changes.
I tried using SEQNUM, with a RESTART on the value in pos 1, but that gave me the following, quickly followed with me slapping my head when I realised I was asking the impossible of good old RESTART :
Code: |
1234567890
----------
01 CODE1
02 CODE4
01 CODE3
02 CODE9
03 CODEX
01 CODEEE |
Can anyone point me in the direction of an alternative approach with DFSORT (or even ICETOOL - i'm not a fussy man ) which will give me the results i'm after.
Thanks in advance. |
|
Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7310 Location: Inside the Matrix
|
|
|
|
Instead of the SEQNUM with RESTART, use IFTHEN=(WHEN=GROUP( with PUSH=(col:ID=2). |
|
Back to top |
|
 |
HammerTime
New User
Joined: 26 Sep 2012 Posts: 14 Location: UK
|
|
|
|
Thanks Bill, I'll give that a go in the morning. I've been using DFSORT for years, but only very recently discovered SEQNUM, and I've never seen the GROUP function.
Every day is a school day!
Will report back tomorrow. |
|
Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
HammerTime wrote: |
Hi all, i'm pulling my hair out with what I can only imagine is a simple bit of logic!
I have an input which looks something like this:
Code: |
1234567890
----------
A CODE1
A CODE4
B CODE3
B CODE9
B CODEX
C CODEEE |
The reason I'm struggling here is that the values I have provided in my example of A/B/C are very variable inputs (hundreds of possibilities here), so I can't just use a simple replace. What that incoming value is, is not important. What is important is that I have a 'sequence number' (or incremental numerical label starting at 1), which increments whenever the value in pos 1 changes.
|
Hammertime,
As bill suggested it is quite easy. However if you have hundreds of possible values how are you going to fit it in 2 bytes? Don't you need more than that?
Either way here is a sample for 2 byte id. You can adjust length of n in ID=n based on your requirements.
Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
A CODE1
A CODE4
B CODE3
B CODE9
B CODEX
C CODEEE
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,1),PUSH=(ID=2))
//* |
|
|
Back to top |
|
 |
HammerTime
New User
Joined: 26 Sep 2012 Posts: 14 Location: UK
|
|
|
|
Thank you so much guys, that is exactly what I wanted. Interesting to see that the PUSH=(ID=X) actually overlays the incoming data with the sequence. Perfect for my needs (as mentioned, I'm not actually interested in my incoming identifier, only in the grouping), but worth noting for others.
Skolusu, the incoming identifier field which I represented in my example above as A/B/C is actually 7 bytes. As mentioned, the PUSH overlays the first X bytes of that, for my purposes I needed X to be 3 (this will be compared against a matching sequence later in my JCL), so to clean things up for my purposes I just space filled the remainder of my incoming identifier (eg: the 4 byes after X).
The code i've used in the end is:
Code: |
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,7),PUSH=(ID=3))
OUTREC FIELDS=(1,3,C' ',8,72) |
Once again, sincere thanks. It's great to learn more about the seemingly endless functionality of DFSORT! |
|
Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7310 Location: Inside the Matrix
|
|
|
|
Not exactly. PUSH has a column-number. For fixed-length records the default column is one. For variable-length records the default column is five.
Code: |
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,7),PUSH=(1:ID=3)),
IFTHEN=(WHEN=INIT,OVERLAY=(4:4X)) |
|
|
Back to top |
|
 |
|