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 

Dfsort- Sort Header with Detail Records

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


Joined: 20 May 2004
Posts: 97
Topics: 43
Location: hyderabad, India

PostPosted: Fri Aug 20, 2004 1:30 am    Post subject: Dfsort- Sort Header with Detail Records Reply with quote

hi all,

i have a following requirement to be solved using SORT.

i have a INPUT file with following contents:
Code:

main-header
subheader-1
subheader-2
subheader-3
detail-line-1
detail-line-2
detail-line-3

in the above input file MAIN-HEADER has the record indicator of 'A'.
in the above input file SUB-HEADER's has the record indicator of 'B'.
in the above input file DETAIL-LINE's has the record indicator of 'D'.
record indicators are the first byte.

my requirement is to create a output file whose contents should b like this:
Code:

main-header
subheader-1
detail-line-1
subheader-2
detail-line-2
subheader-3
detail-line-3


Thanks in advance
_________________
Priya Ranjan Mohanty
Consultant
Kanbay Software (I) pvt. Ltd.
Hyderabad
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Aug 20, 2004 5:46 am    Post subject: Reply with quote

Pzmohanty,

The following DFSORT/ICETOOL Jcl will give you the desired results. I assumed that your input file is of 80 bytes in length and is of FB format. I also assumed that the indicator to identify the records is in pos 1.

A brief explanation of the job. This job is based on the trick of sequentially numbering the like records. for more explanation check this link

http://www.mvsforums.com/helpboards/viewtopic.php?p=12751

The first sort operator sorts the file on the identifier which is in the first byte. We add a seqnum to all the records using OUTREC FIELDS. Now using sections and MIN on the trailer3 parm we get the lowest of the seqnum for each equal group key. We also create another file with all the records. we also write the indicator at 81st byte and using a change command we only change the subheader indicator 'B' to a 'D' so that we can sort on that indicator later.

The SPLICE operator then takes in these 2 files concatenated and populates the key break seqnum for all the records. The formula is to get the key break seqnum is Seqnum - min + 1

The last SORT operator takes in the output of splice which has the records numbered, we just sort on the indicator and record number to acheive the desired results. And using OUTREC we remove the additional bytes we added at the end.

Code:

//STEP0100 EXEC PGM=ICETOOL                         
//TOOLMSG  DD SYSOUT=*                               
//DFSMSG   DD SYSOUT=*                               
//IN       DD *                                     
A-MAIN-HEADER                                             
B-SUBHEADER-1                         
B-SUBHEADER-2                         
B-SUBHEADER-3                         
D-DETAIL-LINE-1                                       
D-DETAIL-LINE-2                                       
D-DETAIL-LINE-3                                       
//T1       DD DSN=&T1,DISP=(,PASS),UNIT=SYSDA,SPACE=(CYL,(1,1),RLSE)
//T2       DD DSN=&T2,DISP=(,PASS),UNIT=SYSDA,SPACE=(CYL,(X,Y),RLSE)
//CON      DD DSN=&T1,DISP=OLD,VOL=REF=*.T1                         
//         DD DSN=&T2,DISP=OLD,VOL=REF=*.T2                         
//T3       DD DSN=&T3,DISP=(,PASS),UNIT=SYSDA,SPACE=(CYL,(X,Y),RLSE)
//OUT      DD SYSOUT=*                                             
//TOOLIN   DD *                                                     
  SORT FROM(IN) USING(CTL1)                                         
  SPLICE FROM(CON) TO(T3) ON(1,1,CH) -                             
  WITH(1,89) WITHALL USING(CTL2)                                 
  SORT FROM(T3) USING(CTL3)                                         
//CTL1CNTL DD *                                           
  SORT FIELDS=(1,1,CH,A)                                   
  OUTREC FIELDS=(1,80,                                     
                 81:1,1,CHANGE=(1,C'B',C'D'),NOMATCH=(1,1),
                 SEQNUM,8,ZD,8X)                           
  OUTFIL FNAMES=T1,NODETAIL,REMOVECC,                     
  SECTIONS=(1,1,TRAILER3=(1,89,MIN=(82,8,ZD,M11,LENGTH=8)))
  OUTFIL FNAMES=T2                                         
//CTL2CNTL DD *                                           
  OUTFIL FNAMES=T3,                                       
  OUTREC=(1,81,                                           
         ((82,8,ZD,SUB,90,8,ZD),ADD,+1),EDIT=(TTTTTTTT))   
//CTL3CNTL DD *                                           
  OPTION EQUALS                                           
  SORT FIELDS=(81,9,CH,A)                                 
  OUTFIL FNAMES=OUT,OUTREC=(1,80)                         
/*                                                         


Hope this helps...

Cheers

Kolusu

Ps: If your shop has syncsort then change the pgm name synctool. But you need to have the latest version of syncsort(atleast syncsort z/os 1.1CRI TPF3 )
_________________
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