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 a file which has a header and detail records

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


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Sat Nov 26, 2005 12:08 pm    Post subject: Sort a file which has a header and detail records Reply with quote

The input file has header indicated with 1 in pos 1
and detail records with 2 in pos 1. I could have several set of records in the file.

Input file (15 bytes)
Code:

1950.00   
2GGGGGGGG       
2KEY2     
2AAAAAA   
2BALTYPE   
2YEAR
2KEY1   
2CCCCCCCCC
2ZZZZZZZZZZZ   
2DDDDDDDD 
2FFFFFFFFFF

My job below works for just 1 set of records. If there is more than 1
set of records, all the header gets sorted together and then the data records. How can I sort each set of 1 and 2 records and then the next and so on?

Code:
 
* PUT SPECIAL KEY OF '4' IN 16 FOR DATA RECORDS.             
   INREC IFTHEN=(WHEN=INIT,OVERLAY=(16:C'4')),               
* FOR HEADER RECORD, PUT SPECIAL KEY OF '0' IN 16.           
       IFTHEN=(WHEN=(1,1,CH,EQ,C'1'),OVERLAY=(16:C'0')),     
* FOR KEY1 RECORD, PUT SPECIAL KEY OF '1' IN 16.             
       IFTHEN=(WHEN=(2,4,CH,EQ,C'KEY1'),OVERLAY=(16:C'1')),   
* FOR KEY2 RECORD, PUT SPECIAL KEY OF '2' IN 16.             
       IFTHEN=(WHEN=(2,4,CH,EQ,C'KEY2'),OVERLAY=(16:C'2'))   
* SORT BY KEYS.
   SORT FIELDS=(16,1,CH,A,2,15,CH,A)                         
* REMOVE SPECIAL KEY.                                         
   OUTREC FIELDS=(1,15)                                       
/*         


I get this output if there is just one set of records

Code:

1950.00   
2KEY1     
2KEY2     
2AAAAAA   
2BALTYPE
2CCCCCCCCC
2DDDDDDDD 
2FFFFFFFFFF
2GGGGGGGG
2YEAR 
2ZZZZZZZZZZZ 

for 2 sets of records I get

1950.00
1670.00   
2KEY1 
2KEY1   
2KEY2   
2KEY2
2AAAAAA   
2AAAAAA   
........

Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Sat Nov 26, 2005 12:43 pm    Post subject: Reply with quote

You need to use DFSORT's IFTHEN for "group sorting" - something similar to the example shown in the "Sort groups of records" Smart DFSORT Trick at:

http://www.ibm.com/servers/storage/support/software/sort/mvs/tricks/

If you need more specific help on this, I need to know if you want the groups sorted by the 1 record value (e.g. the 670.00 group before the 950.00 group) or in their original order (e.g. the 950.00 group before the 670.00 group). Also, do you want the KEY1 and KEY2 records to sort before the rest of the data records as implied in your job?

Actually, it would help if you would show an example of your input records with two or more groups and what you want the output records to look like.
_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort


Last edited by Frank Yaeger on Thu Sep 07, 2006 6:55 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shuko
Beginner


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Sat Nov 26, 2005 3:10 pm    Post subject: Reply with quote

Sample Input

KEY1 and KEY2 to be sorted before the data records

Code:


1950.00   
2GGGGGGGG       
2KEY2     
2AAAAAA   
2BALTYPE   
2YEAR
2KEY1   
2CCCCCCCCC
2ZZZZZZZZZZZ   
2DDDDDDDD 
2FFFFFFFFFF
1650.00   
2GGGGGGGG       
2KEY2     
2AAAAAA   
2BALTYPE   
2YEAR
2KEY1   
2CCCCCCCCC
2XYZYYZXYZXYZ   
2DDDDDDDD 
2FFFFFFFFFF


Desired output

Code:

1950.00   
2KEY1     
2KEY2     
2AAAAAA   
2BALTYPE
2CCCCCCCCC
2DDDDDDDD 
2FFFFFFFFFF
2GGGGGGGG
2YEAR 
2ZZZZZZZZZZZ 
1650.00   
2KEY1     
2KEY2     
2AAAAAA   
2BALTYPE
2CCCCCCCCC
2DDDDDDDD 
2FFFFFFFFFF
2GGGGGGGG
2XYZYYZXYZXYZ
2YEAR 


Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Sun Nov 27, 2005 10:53 am    Post subject: Reply with quote

Shuko,

Here's a DFSORT job that will do what you asked for:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=...  input file (FB/15)
//SORTOUT DD DSN=...  output file (FB/15)
//SYSIN    DD    *
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(17:SEQNUM,8,ZD)),
        IFTHEN=(WHEN=(1,1,CH,EQ,C'1'),
                OVERLAY=(16:C'A',17:SEQNUM,8,ZD)),
        IFTHEN=(WHEN=(1,1,CH,NE,C'1'),
                OVERLAY=(16:C'C',25:SEQNUM,8,ZD,
                         17:17,8,ZD,SUB,25,8,ZD,M11,LENGTH=8),
                HIT=NEXT),
        IFTHEN=(WHEN=(2,3,CH,EQ,C'KEY'),
                OVERLAY=(16:C'B'))
  OPTION EQUALS
  SORT FIELDS=(17,8,ZD,A,16,1,CH,A,2,14,CH,A)
  OUTREC FIELDS=(1,15)
/*

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shuko
Beginner


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Mon Nov 28, 2005 2:07 am    Post subject: Reply with quote

Thank you Frank.
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 -> 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