How to sort groups of records based on the header



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

How to sort groups of records based on the header

Postby Irene Ioujanina » Mon Feb 23, 2009 10:13 pm

Hi, May I please ask again. If I have groups of records: each group starts with one record of the header followed by one to many records of details. I would like the order of records within the group does NOT change, but all groups will be ordered by the header value, so the groups with the same headers will be together. If the header is the same - it doesn't matter which group comes first, but the details records inside the group of each header will not be changed.

Thanking in advance,
Input:
---------
header A2
data1
data2
data3
header A3
data4
data5
header A1
data6
data7
header A3
data8
header A2
data9

( the headers start with the constant 'header' and it is sorted by the pos 8-9 in the header )

Output:
---------
header A1
data6
data7
Header A2
data1
data2
data3
header A2
data9
header A3
data4
data5
header A3
data8

Irene
Irene Ioujanina
 
Posts: 27
Joined: Thu Feb 21, 2008 6:42 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to sort groups of records based on the header

Postby skolusu » Mon Feb 23, 2009 11:03 pm

Irene Ioujanina ,

You can use the technique discussed in the "Sort groups of records" Smart DFSORT Trick at:

http://www.ibm.com/systems/support/stor ... vs/tricks/
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
skolusu
 
Posts: 586
Joined: Wed Apr 02, 2008 10:38 pm
Has thanked: 0 time
Been thanked: 39 times

Re: How to sort groups of records based on the header

Postby Irene Ioujanina » Mon Feb 23, 2009 11:20 pm

Thank you for your responce. It seems it is a diferent situation: they sorted the records within each group,-and I want the records within each group are NOT sorted, but the groups (with the unsorted records) will be sorted based on the header value.
for instance- the input:
header A2
9999999
1111111
22222222
header A1
44444
33333
header A2
555555

will became as output:
header A1
44444
33333
header A2
9999999
1111111
2222222
header A2
555555

Thank you anyway for providing a very useful link to the sort tricks :)
Irene Ioujanina
 
Posts: 27
Joined: Thu Feb 21, 2008 6:42 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to sort groups of records based on the header

Postby Frank Yaeger » Tue Feb 24, 2009 12:01 am

You can use a DFSORT job like the following to do what you asked for. I assumed your input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes.

//S1    EXEC  PGM=SORT
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
header A2
9999999
1111111
22222222
header A1
44444
33333
header A2
555555
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  OPTION EQUALS
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,6,CH,EQ,C'header'),
    PUSH=(81:8,2))
  SORT FIELDS=(81,2,ZD,A)
  OUTFIL BUILD=(1,80)
/*
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
User avatar
Frank Yaeger
Global moderator
 
Posts: 1079
Joined: Sat Jun 09, 2007 8:44 pm
Has thanked: 0 time
Been thanked: 15 times

Re: How to sort groups of records based on the header

Postby Irene Ioujanina » Tue Feb 24, 2009 12:28 am

Thank you so much. :)
Irene Ioujanina
 
Posts: 27
Joined: Thu Feb 21, 2008 6:42 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post