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

Trying to assign a variable input a numerical 'label'


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
HammerTime

New User


Joined: 26 Sep 2012
Posts: 14
Location: UK

PostPosted: Fri Feb 07, 2014 1:47 am
Reply with quote

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 icon_biggrin.gif ) which will give me the results i'm after.

Thanks in advance.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Fri Feb 07, 2014 2:43 am
Reply with quote

Instead of the SEQNUM with RESTART, use IFTHEN=(WHEN=GROUP( with PUSH=(col:ID=2).
Back to top
View user's profile Send private message
HammerTime

New User


Joined: 26 Sep 2012
Posts: 14
Location: UK

PostPosted: Fri Feb 07, 2014 3:03 am
Reply with quote

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

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Fri Feb 07, 2014 5:20 am
Reply with quote

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

New User


Joined: 26 Sep 2012
Posts: 14
Location: UK

PostPosted: Fri Feb 07, 2014 1:42 pm
Reply with quote

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

Moderator Emeritus


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

PostPosted: Fri Feb 07, 2014 2:10 pm
Reply with quote

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
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts JCL (SET) variables in input stream data JCL & VSAM 0
This topic is locked: you cannot edit posts or make replies. I HAVE 2 INPUT FILES WITH SAME LAYOUT... COBOL Programming 6
No new posts Using sort on VB records based on off... DFSORT/ICETOOL 6
No new posts FILE STATUS - 39 ON VARIABLE LENGTH V... COBOL Programming 2
No new posts JOINKEYS to match two input files on ... DFSORT/ICETOOL 3
Search our Forums:

Back to Top