Page 1 of 1

Rearranging records from multiple files into one

PostPosted: Thu Oct 08, 2015 1:59 pm
by Aki88
Hello,

We have 'n' PS files DD concatenated, each file has a header record, 'm' number of details records and one tail record.
The final output required is - one head record, all the 'm' details records from all 'n' files sorted on their key, and one tail record with the record count.

This can be easily achieved using multiple SORT steps to split and the merge the files again; the point I am stuck at is when I am trying to build the final output in one single DFSORT step.
What I am able to achieve in one go is:
--> SORT on the key
--> Build the detail records sorted on the key minus the head and tail records using OMIT
--> Build the trailer record with the total record count

Point where I am stuck is building a 'single' header record with the date picked from the input file (all the input files will have same date generated on any given day, so header can be picked from any 1 input file).

Sample data (this is how all the concatenated files sorted on their key would look like); here 'X' records are header records - date inserted is generated by an application program, 'Z' are the details records, '9's are the tail records - 7th byte onwards is the record count of each 'n' file generated by the application program.

Any pointers are much appreciated.

Thanks.

XXX000000DD/MM/YYYY
XXX000000DD/MM/YYYY
XXX000000DD/MM/YYYY
XXX000000DD/MM/YYYY
XXX000000DD/MM/YYYY
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
999999000000080
999999000000080
999999000000080
999999000000080
999999000000080


Desired output:

XXX000000DD/MM/YYYY
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
999999000000320

Re: Rearranging records from multiple files into one

PostPosted: Thu Oct 08, 2015 2:22 pm
by BillyBoyo
Don't use INCLUDE/OMIT COND= on the headers (just the trailers).

In INREC, use IFTHEN=(WHEN=(logicalexpression) to put a SEQNUM in an extension, the logialexpression to be for the headers.

Use OUTFIL with INCLUDE= to keep only the first header (extended SEQNUM of 1), and the data.

Re: Rearranging records from multiple files into one

PostPosted: Thu Oct 08, 2015 2:38 pm
by Aki88
Hello Billy,

My bad, I lost you there at the INREC :(
Below is my current card, relatively a very simple solution:

SORT FIELDS=(1,19,CH,A)                                   
OUTFIL FILES=TEST,REMOVECC,                                 
       OMIT=((1,3,CH,EQ,C'XXX'),OR,(1,3,CH,EQ,C'999')),   
       TRAILER1=(1:C'999999',7:COUNT=(M11,LENGTH=9),16:42X)


This is giving me the below o/p:

ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
999999000000320


Header needs to be added to this; can you kindly explain the solution again; my apologies, having a rough day, even simple solutions are looking Greek and Latin today. :(

Thank you.

Re: Rearranging records from multiple files into one

PostPosted: Thu Oct 08, 2015 3:24 pm
by Aki88
Thanks a ton Billy!

A quick break and clarity prevails :)

Final solution:

SORT FIELDS=(1,19,CH,A)                                       
INREC OVERLAY=(58:SEQNUM,9,ZD)                               
OUTFIL FILES=TEST,REMOVECC,                                     
       OMIT=(((1,3,CH,EQ,C'XXX'),AND,(58,9,ZD,NE,1)),OR,     
              (1,3,CH,EQ,C'999')),                           
       TRAILER1=(1:C'999999',7:COUNT-1=(M11,LENGTH=9),16:42X)


Thanks.

Re: Rearranging records from multiple files into one

PostPosted: Thu Oct 08, 2015 3:36 pm
by BillyBoyo
When you're getting nowhere, a break is always a good idea :-)

You don't need the trailers from the files at all, as you generate one later:

  OMIT COND=(1,3,CH,EQ,C'999')


Saves SORTing a few records and simplifies your OMIT= on OUTFIL.

Nine digits for your sequence number is unrealistic, there's a limit to the number of DD statements in a step. Even if you're going crazy with datasets, five is the most you'll need.

Re: Rearranging records from multiple files into one

PostPosted: Thu Oct 08, 2015 3:48 pm
by Aki88
Aah, yes; OMIT, tweaked that one and the SEQNUM; thanks again Billy.

Regards.