Sort groups of records by data on the second record in a group

1.9k views Asked by At

I am trying to sort group of records. (ie) by date in the second line "100" in the first line is the start of the record. "BBB" is the second line of the record. "CCC" is the thrid line of the record.

Input:

100 AAAAA AAAA AAAA AAAAAAA 
    BBBBB BBBB BBB START :05/01/2014 AT 05:00:00 
          CCCC CCCC CCCC CCCC .
200  AAAA1 AAAA1 AAAA AAAAAAA   
     BBBBB1 BBBB BBB START :01/01/2014 AT 05:00:00 
          CCCC1 CCCC CCCC CCCC . 

I require output as

200  AAAA1 AAAA1 AAAA AAAAAAA    
     BBBBB1 BBBB BBB START :01/01/2014 AT 05:00:00 
          CCCC1 CCCC CCCC CCCC .
100 AAAAA AAAA AAAA AAAAAAA 
    BBBBB BBBB BBB START :05/01/2014 AT 05:00:00 
          CCCC CCCC CCCC CCCC . 

Please provide any suggestions on how to get the above output.

1

There are 1 answers

0
Bill Woodger On

Assumptions: your groups are regular (three records, always in this order); RECFM F/FB (even FBS); LRECL 80 (and in general not "too big").

For the second and third records, IFTHEN=(WHEN=GROUP can easily be used to propagate the date from the second record to the third.

How does that help with the first record? Doesn't. So, instead, on identifying the first record of a group, extend the records and copy the first record onto the second.

Now you only need the second and third record (as the second contains the first).

You will need OUTFIL to exclude the original first records and to create new first records (using the slash operator /).

  OPTION EQUALS
  INREC IFTHEN=(WHEN=GROUP,
                  BEGIN=(1,1,CH,NE,C' '),
                  RECORDS=2,
                  PUSH=(81:SEQ=1,1,80)),
         IFTHEN=(WHEN=INIT,
                  BEGIN=(81,1,CH,EQ,C'2'),
                  RECORDS=2,
                  PUSH=(162:startposofdate,lengthofdate))
   SORT FIELDS=(162,length-of-date,CH,A)
   OUTFIL OMIT=(81,1,CH,EQ,C'1'),
          IFTHEN=(WHEN=(81,1,CH,EQ,C'2').
                    BUILD=(82,80,
                           /,
                           1,80)),
          IFTHEN=(WHEN=NONE,
                    BUILD=(1,80))

That's an outline. Awaiting more detials....