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 

House Number Range

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
Claes
Beginner


Joined: 20 Apr 2015
Posts: 7
Topics: 2
Location: Denmark

PostPosted: Thu Apr 23, 2015 12:03 pm    Post subject: House Number Range Reply with quote

Hi,

I've got the following requirement, that I'd love DFSORT to do for me - although I realize I may need to use an application program..

Basically, I've got a list of streets (identified by an unique id, numeric 8) and house numbers (numeric 3) on that street. My requirement is to make a list of streets with house number intervals. Also, a record must appear for even houseno and another for odd. The trick being, that "holes" in the house numbers may appear. There are no duplicates on StreetId+Houseno combined. Take these examples:

This input:
Code:
streetId  HouseNo
00000001    001
00000001    002
00000001    003
00000001    004
00000001    005
00000001    006
00000001    007
00000001    008

would result in 2 records:
Code:
streetId  HouseNoFrom HouseNoTo  Even/Odd
00000001        001       007        O
00000001        002       008        E

whereas this input:
Code:
streetId  HouseNo
00000001    001
00000001    002
00000001    004
00000001    005
00000001    007
00000001    008

would result in these records (as 003 and 006 are not present in input):
Code:
streetId  HouseNoFrom HouseNoTo  Even/Odd
00000001        001      001         O
00000001        005      007         O
00000001        002      004         E
00000001        008      008         E

Hope this one will bring some joy to you! I welcome anything that can guide me in the right direction. Smile
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Apr 23, 2015 12:22 pm    Post subject: Reply with quote

Claes,

Use the following DFSORT JCL which will give you the desired results.

Code:

//STEP0100 EXEC PGM=SORT                                               
//SYSOUT   DD SYSOUT=*                                                 
//SORTIN   DD *                                                         
00000001    002                                                         
00000001    004                                                         
00000001    006                                                         
00000001    008                                                         
00000001    009                                                         
00000001    010                                                         
00000001    011                                                         
00000001    012                                                         
00000001    013                                                         
00000001    014                                                         
00000001    016                                                         
00000001    020                                                         
00000001    022                                                         
00000001    024                                                         
00000001    026                                                         
00000001    028                                                         
//SORTOUT  DD DSN=&&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)             
//SYSIN    DD *                                                         
  OPTION COPY                                                           
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(20:SEQNUM,3,ZD,RESTART=(1,8))),     
  IFTHEN=(WHEN=INIT,                                                   
  OVERLAY=(25:1,8,13,3,UFF,SUB,20,3,ZD,M11,LENGTH=3,                   
           50:3C'9',5X,3C'9',5X)),                                     
  IFTHEN=(WHEN=GROUP,KEYBEGIN=(25,11),PUSH=(40:ID=8)),                 
  IFTHEN=(WHEN=(15,1,BI,EQ,B'.......0'),OVERLAY=(50:13,3,X,13,3)),     
  IFTHEN=(WHEN=(15,1,BI,EQ,B'.......1'),OVERLAY=(58:13,3,X,13,3))       
                                                                       
  OUTFIL REMOVECC,NODETAIL,BUILD=(24X),                                 
  SECTIONS=(40,8,                                                       
  TRAILER3=(1,8,                                                       
            3X,                                                         
            MIN=(58,3,UFF,EDIT=(TTT)),                                 
            3X,                                                         
            MAX=(62,3,UFF,EDIT=(TTT)),                                 
            3X,                                                         
            'O',/,                                                     
            1,8,                                                       
            3X,                                                         
            MIN=(50,3,UFF,EDIT=(TTT)),                                 
            3X,                                                         
            MAX=(54,3,UFF,EDIT=(TTT)),                                 
            3X,                                                         
            'E'))                                                       
//*                                                                     
//STEP0200 EXEC PGM=SORT                                     
//SYSOUT   DD SYSOUT=*                                       
//SORTIN   DD DISP=SHR,DSN=&&T1                               
//SORTOUT  DD SYSOUT=*                                       
//SYSIN    DD *                                               
  OMIT COND=(12,3,CH,EQ,C'999',AND,18,3,CH,EQ,C'000')         
  SORT FIELDS=(1,8,CH,A,24,1,AQ,A),EQUALS                     
  ALTSEQ CODE=(D6C4)                                         
                                                             
  OUTREC IFOUTLEN=48,                                         
  IFTHEN=(WHEN=INIT,OVERLAY=(81:1,8,24,1)),                   
  IFTHEN=(WHEN=GROUP,KEYBEGIN=(81,9),PUSH=(30:12,3)),         
  IFTHEN=(WHEN=INIT,                                         
  OVERLAY=(35:SEQNUM,3,ZD,RESTART=(81,9),START=0,INCR=2,     
           90:30,3,ZD,ADD,35,3,ZD,SUB,12,3,ZD,EDIT=(TTT))),   
  IFTHEN=(WHEN=GROUP,KEYBEGIN=(81,12),PUSH=(40:ID=8))         
                                                             
  OUTFIL REMOVECC,NODETAIL,BUILD=(80X),                       
  HEADER2=('STREET     HOUSEFROM  HOUSETO EVEN/ODD',/,       
           '------     ---------  ------- --------'),         
  SECTIONS=(40,8,                                             
  TRAILER3=(1,8,                                             
            18:MIN=(12,3,UFF,EDIT=(TTT)),                     
            27:MAX=(18,3,UFF,EDIT=(TTT)),                     
            38:24,1))                                         
//* 

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


Joined: 20 Apr 2015
Posts: 7
Topics: 2
Location: Denmark

PostPosted: Fri Apr 24, 2015 4:37 am    Post subject: Reply with quote

Hi Kolusu,

This is a very clean and ingenious solution! I love that you use SECTIONS with MIN and MAX - something that I thought of using myself, but couldn't quite put into code..

Don't know if you did it for clarity, but I think this one can be avoided in the COPY step:
Code:
IFTHEN=(WHEN=GROUP,               
  KEYBEGIN=(25,11),PUSH=(40:ID=8)),
then use
Code:
SECTIONS=(25,11,
instead of
Code:
SECTIONS=(40,8
in OUTFIL. The same is true for a similar construction in the SORT step.


More importently, I think I found a bug. Please use this input:
Code:

00000024    001
00000024    002
00000024    003
00000024    006
00000024    007
00000024    008
00000024    009
00000024    010
00000024    011
00000024    012
00000024    013
00000024    014
00000024    015
00000024    016
00000024    017
00000024    018
00000024    020
00000024    021
00000024    023
00000024    024
00000024    025
00000024    026
00000024    027
00000024    028
00000024    029
00000024    031
00000024    033

I get this output:
Code:

STREET     HOUSEFROM  HOUSETO EVEN/ODD
------     ---------  ------- --------
00000024         001      003        O
00000024         007      017        O
00000024         021      029        O  <=== these should have
00000024         031      033        O  <=== been joined
00000024         002      002        E
00000024         006      018        E <=== these should have
00000024         020      020        E <=== been joined too
00000024         024      028        E
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Apr 24, 2015 10:56 am    Post subject: Reply with quote

Claes,

I added those sections for clarity and in regards to the bug, I will look into it later in the day today. I have something that I need to finish off before I can take a look at it.

Thanks
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Fri Apr 24, 2015 11:03 am    Post subject: Reply with quote

How about a second generated key? One for odd, one for even. Then two OUTFILs (same code, different names) and a MERGE instead of the SORT in the second step?
Back to top
View user's profile Send private message
Claes
Beginner


Joined: 20 Apr 2015
Posts: 7
Topics: 2
Location: Denmark

PostPosted: Fri Apr 24, 2015 1:02 pm    Post subject: Reply with quote

No worries, I'm already enjoying the weekend:)
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Apr 24, 2015 8:23 pm    Post subject: Reply with quote

Claes,

Finally got around looking into this and got it working. Thanks to William Collins aka Bill, I got the job with simple COPY + Merge operations.

Code:

//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN   DD *
00000001    001
00000001    002
00000001    003
00000001    004
00000001    005
00000001    006
00000001    007
00000001    008
00000002    001
00000002    002
00000002    004
00000002    005
00000002    007
00000002    008
00000006    001
00000006    005
00000006    009
00000024    001
00000024    002
00000024    003
00000024    006
00000024    007
00000024    008
00000024    009
00000024    010
00000024    011
00000024    012
00000024    013
00000024    014
00000024    015
00000024    016
00000024    017
00000024    018
00000024    020
00000024    021
00000024    023
00000024    024
00000024    025
00000024    026
00000024    027
00000024    028
00000024    029
00000024    031
00000024    033
00008548    002
00008548    004
00008548    006
00008548    008
00008548    009
00008548    010
00008548    011
00008548    012
00008548    013
00008548    014
00008548    016
00008548    020
00008548    022
00008548    024
00008548    026
00008548    028
//E        DD DSN=&&E,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//O        DD DSN=&&O,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//SYSIN    DD *
  OPTION COPY

  INREC IFTHEN=(WHEN=INIT,
  OVERLAY=(18:13,3,                              $ FOR ODD
           30:13,3)),                            $ FOR EVEN
  IFTHEN=(WHEN=(15,1,BI,EQ,B'.......1'),         $ CHECK ODD
  OVERLAY=(22:SEQNUM,3,ZD,START=1,INCR=2,        $ SEQ AT 1 INCR BY 2
              RESTART=(1,8),                     $ FOR KEY CHANGE
           30:3X)),                              $ SPACE OUT EVEN
  IFTHEN=(WHEN=(15,1,BI,EQ,B'.......0'),         $ CHECK EVEN
  OVERLAY=(18:3X,                                $ SPACE OUT ODD
           34:SEQNUM,3,ZD,START=2,INCR=2,        $ SEQ AT 2 INCR BY 2
              RESTART=(1,8)))                    $ FOR KEY CHANGE

  OUTREC IFTHEN=(WHEN=(18,1,CH,GT,C' '),         $ FOR ODD
  OVERLAY=(26:18,3,ZD,SUB,22,3,ZD,EDIT=(TTT))),  $ RESULT = ODD - SEQ

  IFTHEN=(WHEN=(30,1,CH,GT,C' '),                $ FOR EVEN
  OVERLAY=(38:30,3,ZD,SUB,34,3,ZD,EDIT=(TTT)))   $ RESULT = EVEN - SEQ

  OUTFIL FNAMES=E,INCLUDE=(30,1,CH,GT,C' '),     $ EVEN TEMP FILE
  REMOVECC,NODETAIL,BUILD=(25X),
  SECTIONS=(1,8,38,3,                            $ KEY + RESULT
  TRAILER3=(1,8,                                 $ KEY
            3X,                                  $ 3 SPACES
            MIN=(30,3,UFF,EDIT=(TTT)),           $ MIN OF EVEN
            3X,                                  $ 3 SPACES
            MAX=(30,3,UFF,EDIT=(TTT)),           $ MAX OF EVEN
            3X,                                  $ 3 SPACES
            'E2'))                               $ EVEN INDICATOR

  OUTFIL FNAMES=O,INCLUDE=(18,1,CH,GT,C' '),     $ ODD TEMP FILE
  REMOVECC,NODETAIL,BUILD=(25X),
  SECTIONS=(1,8,26,3,                            $ KEY + RESULT
  TRAILER3=(1,8,                                 $ KEY
            3X,                                  $ 3 SPACES
            MIN=(18,3,UFF,EDIT=(TTT)),           $ MIN OF ODD
            3X,                                  $ 3 SPACES
            MAX=(18,3,UFF,EDIT=(TTT)),           $ MAX OF ODD
            3X,                                  $ 3 SPACES
            'O1'))                               $ ODD INDICATOR
//*
//STEP0200 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN01 DD DISP=SHR,DSN=&&O
//SORTIN02 DD DISP=SHR,DSN=&&E
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
  MERGE FIELDS=(01,8,CH,A,                       $ KEY
                25,1,CH,A),EQUALS                $ ODD AND EVEN

  OUTFIL REMOVECC,
  BUILD=(01:01,8,                                $ KEY
         18:12,3,                                $ RANGE START
         27:18,3,                                $ RANGE END
         38:24,1),                               $ INDICATOR

  HEADER2=('STREET     HOUSEFROM  HOUSETO EVEN/ODD',/,
           '------     ---------  ------- --------')
//*


The output from this is

Code:

STREET     HOUSEFROM  HOUSETO EVEN/ODD
------     ---------  ------- --------
00000001         001      007        O
00000001         002      008        E
00000002         001      001        O
00000002         005      007        O
00000002         002      004        E
00000002         008      008        E
00000006         001      001        O
00000006         005      005        O
00000006         009      009        O
00000024         001      003        O
00000024         007      017        O
00000024         021      033        O
00000024         002      002        E
00000024         006      020        E
00000024         024      028        E
00008548         009      013        O
00008548         002      016        E
00008548         020      028        E

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


Joined: 20 Apr 2015
Posts: 7
Topics: 2
Location: Denmark

PostPosted: Mon Apr 27, 2015 5:36 am    Post subject: Reply with quote

Hi Kolusu, many thanks for this!! Smile I've got some other stuff to do this week, but will get back to it as soon as I possible can. Then I'll run a test for both this job and Bill's (from the other site).
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Mon Apr 27, 2015 6:47 am    Post subject: Reply with quote

Claes,

You're not going to beat this solution (except by using symbols as well, of course).

It is simple, robust, and efficient.

It has five IFTHENs, including two pairs and an INIT. So just two conditions to be understood.

It relies on simply generating a match-key from the relationship between a rigorous sequence number and a sparse sequence number. And doing that twice, for odd numbers, and even numbers. Nothing to go wrong beyond getting the field starts and sizes correct. Create two files to take advantage of the data being in sequence except for the odd/even split. It uses the MIN and MAX from OUTFIL reporting features, so key-changes are handled automatically. No chance at all of data "bleeding" from one key to another.

One pass of the data to do the processing (to separate files). One pass of the data to merge.

It's no contest. This will work. The other one has to be tested Smile
Back to top
View user's profile Send private message
Claes
Beginner


Joined: 20 Apr 2015
Posts: 7
Topics: 2
Location: Denmark

PostPosted: Mon Apr 27, 2015 9:22 am    Post subject: Reply with quote

Bill, I just want to compare your output to Kolusu's - and if identical, I'm positive you both got it right. That's all Smile

Of course, I'll compare the ressources used by both too - but I have no doubt that Kolusu's will be best in that compartment. Wink

Again, thanks for your excellent work, both of you!
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Apr 27, 2015 11:07 am    Post subject: Reply with quote

Claes wrote:
Hi Kolusu, many thanks for this!! Smile I've got some other stuff to do this week, but will get back to it as soon as I possible can. Then I'll run a test for both this job and Bill's (from the other site).


Claes,

No rush at all.
_________________
Kolusu
www.linkedin.com/in/kolusu
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