Posted: Thu Apr 23, 2015 12:03 pm Post subject: House Number Range
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 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:
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
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Fri Apr 24, 2015 10:56 am Post subject:
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.
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?
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
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
Hi Kolusu, many thanks for this!! 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).
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
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Mon Apr 27, 2015 11:07 am Post subject:
Claes wrote:
Hi Kolusu, many thanks for this!! 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).
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