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 

SORT challenge about headers, details & trailers

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Mainframe Challenge
View previous topic :: View next topic  
Author Message
Alain Benveniste
Beginner


Joined: 04 May 2003
Posts: 92
Topics: 4
Location: Paris, France

PostPosted: Fri Dec 24, 2004 11:48 am    Post subject: SORT challenge about headers, details & trailers Reply with quote

Some of you enjoy playing brain-teasers.

Few months ago, I received a mail offline from India about a need very close to this one :
[url]
http://www.mvsforums.com/helpboards/viewtopic.php?t=2795&highlight=header+sort
[/url]
Here are the terms to make it a little more harder :

1) How can I SORT (ascendant) unpredictable number of details records between multiple headers records

Input is :
Code:

HDR1
A
HDR2
B
A
HDR3
C
B
A


Output should be :
HDR1
A
HDR2
A
B
HDR3
A
B
C

2) How can I SORT (ascendant) unpredictable number of details records between multiple headers records AND trailers records

Input is :
Code:

HDR1
A
TRL1
HDR2
B
A
TRL2
HDR3
C
B
A
TRL3


Output should be :
Code:

HDR1
A
TRL1
HDR2
A
B
TRL2
HDR3
A
B
C
TRL3


3) Find a solution with your actual level of DFSORT/SYNCSORT and/or try to use the new DFSORT enhancements.

For your info I am also in the party for
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Sat Dec 25, 2004 6:16 am    Post subject: Reply with quote

Alain,

I have one question. Is there a way to differentiate two Headers/Trailers. Something like HDR1, HDR2....(where the number differentiates the two headers) ?

Thanks,
Phantom
Back to top
View user's profile Send private message
Alain Benveniste
Beginner


Joined: 04 May 2003
Posts: 92
Topics: 4
Location: Paris, France

PostPosted: Sat Dec 25, 2004 9:21 am    Post subject: Reply with quote

Phantom,

The only thing you can test is 'HDR' and 'TRL'. What comes after is unpredictable.
The numbers are just here to say that you have to preserve the coherence in the final solution.
So no, there is no way to differentiate HDR/TRL between them...

Good luck
Alain
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Tue Dec 28, 2004 7:33 am    Post subject: Reply with quote

Alain,

Do you have a solution for this (using existing versions of Syncsort/Dfsort)? If so, how many pass did u take ? (Don't give me the solution. Just tell me how many passes you took).

After breaking my head for the past 2-3 days I think I got a solution (using OLD Syncsort V 3.7). But I can't guarantee on the no. of passes. The no. of passes will be dependant (vary dynamically) on the no. of Headers.

Total no. of Passes =
2 full pass on the input data +
(2 * n) passes over dynamically created control cards. (Where n = no. of headers).

NOTE: There will be only 1 SORT over the data. Others are just COPY

I've not completed yet. I'll get back soon.

Is this by any means Acceptable ? !!!

Thanks,
Phantom
Back to top
View user's profile Send private message
Alain Benveniste
Beginner


Joined: 04 May 2003
Posts: 92
Topics: 4
Location: Paris, France

PostPosted: Tue Dec 28, 2004 10:35 am    Post subject: Reply with quote

Phantom,
I have a solution for the both cases. I wrote it with dfsort for a syncsort user. The feedback i had is that the solution is compatible. But I don't know what syncsort 3.7 can do.
The solution I will give has none restriction., none dependancies...

For HDR&Details = 2 passes
For HDR,Details&TRL = 3 passes

With the new dfsort features, only 1 pass and 1 jcl responds for the both cases !

My opinion, phantom, is that you shouldn't spend your free time finding a restricted solution; but a global one. Wink

Happy to find a hard sort gamer

Alain
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Tue Dec 28, 2004 10:51 am    Post subject: Reply with quote

Alain,

Code:

For HDR&Details = 2 passes


Uffff....Pal, I'm dead. !!!! Sad Sad Sad

In the link that you posted with ur question, Kolusu had said that he can't think if a way to achieve this using the traditional features of Sort. Me too...Can't think of a direct way.

I just can't keep thinking of the samething again & again. Could you please send ur solution Offline. I completed my solution, it takes 2 * n + 3 passes (where n = no. of headers), out of which (2 * n) passes were required just to convert the data as shown below.

Code:

Input:
H1
D3
D2
D1
H2
D1
H3
D5
D3
D1
D2
D4


Output:
H1        1
D3        2
D2        2
D1        2
H2        3
D1        4
H3        5
D5        6
D3        6
D1        6
D2        6
D4        6


Finally I sort on the CONSTANT char which I added at the end and then sort on the actual data which will get me the correct order.

I can't guess anymore......Please send me your solution offline.

Thanks,
Phantom
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Dec 28, 2004 11:54 am    Post subject: Reply with quote

Alain Benveniste,

Quote:

For HDR&Details = 2 passes


hmm I posted a solution in this topic for sorting detail records. check the 13th post from the bottom.

http://www.mvsforums.com/helpboards/viewtopic.php?t=1850&highlight=splice

you can take the 1st 2 passes in that solution.

I am on vacation and I don't have a way to test the sorting of header , detail and trailer

kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Dec 29, 2004 12:55 am    Post subject: Reply with quote

Deleted

phantom
Back to top
View user's profile Send private message
Alain Benveniste
Beginner


Joined: 04 May 2003
Posts: 92
Topics: 4
Location: Paris, France

PostPosted: Wed Dec 29, 2004 4:51 am    Post subject: Reply with quote

Phantom,

Kolusu says
Code:

you can take the 1st 2 passes in that solution.

The splice is at the 3thrd place. I send you the logic & the jcl offline.

Alain
Back to top
View user's profile Send private message
Alain Benveniste
Beginner


Joined: 04 May 2003
Posts: 92
Topics: 4
Location: Paris, France

PostPosted: Wed Dec 29, 2004 4:54 am    Post subject: Reply with quote

Kolusu,

If you want to try, I will wait for you before posting the solutions.

alain
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Dec 29, 2004 5:02 am    Post subject: Reply with quote

I'm sorry guys. Kolusu explained me everything offline.

Thanks,
Phantom
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Dec 29, 2004 5:17 am    Post subject: Reply with quote

Alain Benveniste,


Go ahead with your solutions as I will not be able to work on them right now.

Thanks

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Thu Dec 30, 2004 2:44 am    Post subject: Reply with quote

Alain,

Code:

For HDR,Details&TRL = 3 passes


Kolusu gave me his solution with 2 Passes for HDR + Detail records. I just modified it a bit for HDR + Detail + TRL records. And that also took just 2 passes. I have sent you (& Kolusu) the solution Offline.

Code:

I send you the logic & the jcl offline.


I didn't receive any note from you yet. Could you please resend your solutions.

Thanks,
Phantom
Back to top
View user's profile Send private message
Alain Benveniste
Beginner


Joined: 04 May 2003
Posts: 92
Topics: 4
Location: Paris, France

PostPosted: Wed Jan 05, 2005 8:26 am    Post subject: Reply with quote

The logic is identical for the both cases.
Code:

Col1   Col2    Col3    Col4    Col5    Col6
                                       
HDR1   00001   00001           00001   A
A      00002           00001   00001   B
TRL1   00003           00002   00001   B
HDR2   00004   00002           00002   A
A      00005           00003   00002   B
TRL2   00006           00004   00002   B
HDR3   00007   00003           00003   A
C      00008           00005   00003   B
B      00009           00006   00003   B
A      00010           00007   00003   B
TRL3   00011           00008   00003   B
HDR4   00012   00004           00004   A
D      00013           00009   00004   B
C      00014           00010   00004   B
B      00015           00011   00004   B
A      00016           00012   00004   B
TRL4   00017           00013   00004   B

Col2: INREC SEQNUM all the records
Col3: SEQNUM only EQ,C'HDR'
Col4: SEQNUM only NE,C'HDR'
COL5: IF Col1='HDR' THEN Col5=Col3
ELSE Col5=Col2-Col4
Col6: IF Col1='HDR' THEN Col6='A'
ELSE Col6='B'

Here is the jcl for HDR only.
Code:

//STEP0001 EXEC PGM=ICETOOL
//DFSMSG   DD SYSOUT=*
//TOOLMSG  DD SYSOUT=*
//TOOLIN   DD *
  COPY FROM(IN)             USING(ICE0)
  SORT FROM(MERGE) TO(OUTX) USING(ICE1)
/*
//IN       DD *
HDR1
A
HDR2
B
A
HDR3
C
B
A
HDR4
D
C
B
A
/*
//OUT1     DD DSN=&&ST01FI01,
//            DISP=(NEW,DELETE,DELETE),
//            UNIT=SYSDA,
//            SPACE=(TRK,(1,0,0),RLSE),
//            DCB=(DSORG=PS,RECFM=FB,LRECL=96)
//OUT2     DD DSN=&&ST01FI02,
//            DISP=(NEW,DELETE,DELETE),
//            UNIT=SYSDA,
//            SPACE=(TRK,(1,0,0),RLSE),
//            DCB=(DSORG=PS,RECFM=FB,LRECL=96)
//MERGE    DD DSN=*.OUT1,VOL=REF=*.OUT1,DISP=(SHR,DELETE,DELETE)
//         DD DSN=*.OUT2,VOL=REF=*.OUT2,DISP=(SHR,DELETE,DELETE)
//OUTX     DD SYSOUT=*
//ICE0CNTL DD *
  INREC  FIELDS=(1,80,SEQNUM,5,ZD,START=1,INCR=1)
  OUTFIL FNAMES=OUT1,
         INCLUDE=(1,3,CH,EQ,C'HDR'),
         OUTREC=(1,80,C'00000',SEQNUM,5,ZD,START=1,INCR=1,C'     A')
  OUTFIL FNAMES=OUT2,
         OMIT=(1,3,CH,EQ,C'HDR'),
         OUTREC=(1,85,SEQNUM,5,ZD,START=1,INCR=1,C'     B')
/*
//ICE1CNTL DD *
  OPTION EQUALS
  INREC  FIELDS=(1,90,(81,5,ZD,SUB,86,5,ZD),M11,LENGTH=5,96,1)
  SORT   FIELDS=(91,5,ZD,A,96,1,CH,A,1,1,CH,A)
  OUTREC FIELDS=(1,80)
/*

Here are the jcl for HDR&TRL from Phantom & Kolusu very similar to each one
Code:

//STEP0100 EXEC PGM=SYNCTOOL     
//DFSMSG   DD SYSOUT=*           
//TOOLMSG  DD SYSOUT=*           
//IN       DD *                   
HDR1                             
A                                 
TLR1                             
HDR2                             
B                                 
A                                 
TLR2                             
HDR3                             
C                                 
B                                 
A                                 
TLR3                             
HDR4                             
D                                 
C                                 
B                                                               
A                                                               
TLR4                                                           
//T1       DD DSN=&&T1,DISP=(,PASS)                             
//T2       DD DSN=&&T2,DISP=(,PASS)                             
//CON      DD DSN=*.T1,VOL=REF=*.T1,DISP=SHR                   
//         DD DSN=*.T2,VOL=REF=*.T2,DISP=SHR                   
//OUT      DD SYSOUT=*                                         
//TOOLIN   DD *                                                 
   COPY FROM(IN)  USING(CTL1)                                   
   SORT FROM(CON) USING(CTL2)                                   
//CTL1CNTL DD *                                                 
  INREC  FIELDS=(1,80,SEQNUM,8,ZD)                             
  OUTFIL FNAMES=T1,INCLUDE=(1,3,CH,EQ,C'HDR'),                 
         OUTREC=(1,80,8C'0',SEQNUM,8,ZD,C'H')                   
  OUTFIL FNAMES=T2,SAVE,                                       
         OUTREC=(1,88,SEQNUM,8,ZD,C'Z')                             
//CTL2CNTL DD *                                                 
  OPTION EQUALS                                                 
  INREC  FIELDS=(1,96,(81,8,ZD,SUB,89,8,ZD),M11,LENGTH=8,97,1)   
  SORT   FIELDS=(97,8,ZD,A,105,1,CH,A,1,3,CH,A)                 
  OUTREC FIELDS=(1,80)                                           
  OUTFIL FNAMES=OUT                                             
/*

Code:

//STEP0100 EXEC PGM=SYNCTOOL     
//DFSMSG   DD SYSOUT=*           
//TOOLMSG  DD SYSOUT=*           
//IN       DD *                   
HDR1                             
A                                 
TLR1                             
HDR2                             
B                                 
A                                 
TLR2                             
HDR3                             
C                                 
B                                 
A                                 
TLR3                             
HDR4                             
D                                 
C                                 
B                                                               
A                                                               
TLR4                                                           
//T1       DD DSN=&&T1,DISP=(,PASS)                             
//T2       DD DSN=&&T2,DISP=(,PASS)                             
//CON      DD DSN=*.T1,VOL=REF=*.T1,DISP=SHR                   
//         DD DSN=*.T2,VOL=REF=*.T2,DISP=SHR                   
//OUT      DD SYSOUT=*                                         
//TOOLIN   DD *                                                 
   COPY FROM(IN)  USING(CTL1)                                   
   SORT FROM(CON) USING(CTL2)                                   
//CTL1CNTL DD *                                                 
  INREC  FIELDS=(1,80,SEQNUM,8,ZD)                             
  OUTFIL FNAMES=T1,INCLUDE=(1,3,CH,EQ,C'HDR'),                 
         OUTREC=(1,80,8C'0',SEQNUM,8,ZD,C'H')                   
  OUTFIL FNAMES=T2,SAVE,                                     
         OUTREC=(1,88,SEQNUM,8,ZD,                           
                 1,3,CHANGE=(1,C'TLR',C'Z'),NOMATCH=(C'I'))
//CTL2CNTL DD *                                                 
  OPTION EQUALS                                                 
  INREC  FIELDS=(1,96,(81,8,ZD,SUB,89,8,ZD),M11,LENGTH=8,97,1)   
  SORT   FIELDS=(97,8,ZD,A,105,1,CH,A,1,3,CH,A)                 
  OUTREC FIELDS=(1,80)                                           
  OUTFIL FNAMES=OUT                                             
/*

The only thing I can say is that those 2 solutions are better than mine !
I think there is no interest for me to post mine solution : I am simply beaten.

The interest of this challenge was also to reveal that the DFSORT UQ95213 or UQ95214
reduces the number of passes to 1 and that the solution is compatible for the both cases.
Frank gave me a hand really nice on this.
Here are the xxxxCNTL statements :
Code:

0PTION EQUALS
INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,5,ZD)),
      IFTHEN=(WHEN=(1,3,CH,EQ,C'HDR'),
      OVERLAY=(81:SEQNUM,5,ZD,91:C'A')),
      IFTHEN=(WHEN=(1,3,CH,NE,C'HDR'),
      OVERLAY=(86:SEQNUM,5,ZD,91:C'B',
      81:81,5,ZD,SUB,86,5,ZD,M11,LENGTH=5))
SORT FIELDS=(81,5,ZD,A,91,1,CH,A,1,1,CH,A)
OUTREC FIELDS=(1,80)

Alain
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Mainframe Challenge 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