Page 1 of 1

How to sort groups of records based NOT on the header

PostPosted: Fri Feb 03, 2012 8:50 pm
by Irene Ioujanina
Hi,

May I please ask again...
Is it possible to sort groups of records when the sort key is always in the second record pos 10thru14 (and this record is identified as KEY in the first 3 positions). For instance:
HDR 043434
KEY 10001
R01 lllll
R01 KKSDKSKD
HDR 0101010
KEY 10000
R03

Each record has 'record identifier' in the first 3 positions. Each group starts from 'HDR', then goes 'KEY', then can go any number of any different record types(except HDR and KEY). The group of record ends when the next 'HDR' comes, or EOF. The order of records withing each group should not change. The record length let's say 80B.
The result I need :
HDR 0101010
KEY 10000
R03
HDR 043434
KEY 10001
R01 lllll
R01 KKSDKSKD

Thank you so much in advance,

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

PostPosted: Fri Feb 03, 2012 9:34 pm
by Akatsukami
See if Gerry's first sort step is of use to you. Otherwise, you could concatenate all the records in one group, sort those concatenated records, and split them up again, although I daresay that you'd rather avoid that.

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

PostPosted: Fri Feb 03, 2012 10:03 pm
by skolusu
Irene Ioujanina,

The following DFSORT JCL will give you the desired results.

//STEP0100 EXEC PGM=SORT 
//SYSOUT   DD SYSOUT=*   
//SORTIN   DD DSN=Your input FB 808 File,DISP=SHR
//SORTOUT  DD SYSOUT=*                                             
//SYSIN    DD *                                                   
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'HDR'),               
          PUSH=(809:1,808),RECORDS=2),                             
  IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'HDR'),PUSH=(1617:ID=8)),   
  IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'KEY'),PUSH=(1625:5,5))
  SORT FIELDS=(1625,5,CH,A),EQUALS                                 
                                                                   
  OUTFIL IFOUTLEN=808,OMIT=(1,3,CH,EQ,C'HDR'),                     
  IFTHEN=(WHEN=(1,3,CH,EQ,C'KEY'),BUILD=(809,808,/,1,808))         
//*

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

PostPosted: Fri Feb 03, 2012 10:38 pm
by Irene Ioujanina
Thank you so much!