View previous topic :: View next topic
|
Author |
Message |
rajiv rengasamy
New User
Joined: 24 Sep 2008 Posts: 26 Location: Chennai
|
|
|
|
I have a file with multiple blocks of data.
Each block of data has a header and trailer with data records between them. The number of blocks of data is not fixed, it can vary as per Business day.
1 – Header indicator for each block of data
3 - Trailer indicator for each block of data
Data records are prefixed by value 2.
So the file will look as below
Header
1
2Field2 SUBFILED1
2Field2 SUBFILED2
2Field2 SUBFILED3
2Field1 SUBFILED1
2Field5 SUBFILED1
2Field5 SUBFILED3
2Field3 SUBFILED1
3
1
2Field4 SUBFILED1
2Field4 SUBFILED2
2Field4 SUBFILED3
2Field2 SUBFILED1
2Field7 SUBFILED1
2Field3 SUBFILED1
2Field3 SUBFILED2
2Field7 SUBFILED1
3
1
2Field3 SUBFILED1
2Field3 SUBFILED2
2Field3 SUBFILED3
2Field9 SUBFILED1
2Field1 SUBFILED1
2Field2 SUBFILED1
2Field2 SUBFILED2
3
Trailer
I want the data contained between each header, trailer to be stored on Filed and Subfield value in ascending order,for the entire file.
So the result should look as below
Header
1
2Field1 SUBFILED1
2Field2 SUBFILED1
2Field2 SUBFILED2
2Field2 SUBFILED3
2Field3 SUBFILED1
2Field5 SUBFILED1
2Field5 SUBFILED3
3
1
2Field2 SUBFILED1
2Field3 SUBFILED1
2Field3 SUBFILED2
2Field4 SUBFILED1
2Field4 SUBFILED2
2Field4 SUBFILED3
2Field7 SUBFILED1
3
1
2Field3 SUBFILED1
2Field3 SUBFILED2
2Field3 SUBFILED3
2Field9 SUBFILED1
2Field1 SUBFILED1
2Field2 SUBFILED1
2Field2 SUBFILED2
3
Trailer
Do anybody have any recommendation or suggestion. I was planning to write a program with arrays.But wanted to check if this can be done in some simpler or by quicker means.
Thank you.
Regards,
rajiv r |
|
Back to top |
|
|
rajiv rengasamy
New User
Joined: 24 Sep 2008 Posts: 26 Location: Chennai
|
|
|
|
corrected a small mistake in the desired output
Header
1
2Field1 SUBFILED1
2Field2 SUBFILED1
2Field2 SUBFILED2
2Field2 SUBFILED3
2Field3 SUBFILED1
2Field5 SUBFILED1
2Field5 SUBFILED3
3
1
2Field2 SUBFILED1
2Field3 SUBFILED1
2Field3 SUBFILED2
2Field4 SUBFILED1
2Field4 SUBFILED2
2Field4 SUBFILED3
2Field7 SUBFILED1
3
1
2Field1 SUBFILED1
2Field2 SUBFILED1
2Field2 SUBFILED2
2Field3 SUBFILED1
2Field3 SUBFILED2
2Field3 SUBFILED3
2Field9 SUBFILED1
3
Trailer |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
You have posted in the Syncsort part of the forum so have you actually looked into the Synsort manual? You could also look at the DFSOrt tricks document to see if that helps. In that document is a section titled Sort detail records between headers and trailers |
|
Back to top |
|
|
rajiv rengasamy
New User
Joined: 24 Sep 2008 Posts: 26 Location: Chennai
|
|
|
|
Thank you Nic,i'll check. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2022 Location: USA
|
|
|
|
In this case the term "blocks of data" is seriously misleading, at least in mainframe world. This term is mostly related to BLKSIZE/LRECL attributes of datasets.
What needs to be done in this example is called (in SORT terminology) as sorting within "groups of records", but never "blocks".
One of approaches might be:
1) on input, assign sequential "group number" to each record of every group; use INREC IFTHEN=(WHEN=GROUP,... statement.
2) sort the updated intermediate records by 4 fields (GroupNumber, indicator-1-2-3, FieldValue, SubfieldValue); use SORT statement
3) remove unneeded GroupNumber field from output records; use OUTREC or OUTFIL statement.
All can be done in a single SORT run step. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2022 Location: USA
|
|
|
|
Code: |
INREC IFTHEN=(WHEN=GROUP,
* detect either of 'H(eader)', '1', 'T(railer)'
BEGIN=(1,1,SS,EQ,C'H1T'),
PUSH=(81:ID=6)) APPEND GROUP SEQ NUMBER
*
SORT FIELDS=(81,6,ZD,A, GROUP SEQ NUM
1,1,CH,A, LINE TYPE WITHIN GROUP
2,7,CH,A, FIELD
9,9,CH,A) SUBFIELD
*
OUTREC BUILD=(1,80) TRUNCATE GROUP NUMBER
*
END |
|
|
Back to top |
|
|
rajiv rengasamy
New User
Joined: 24 Sep 2008 Posts: 26 Location: Chennai
|
|
|
|
Excellent...Thank you so much..it works precisely as expected.
Just to add a bit more complexity to this,i want some specific type of data say Field38 data elements not be sorted on SUBFILED value and remain in the same order as received in the input file.
So the input file is sorted on Fileds and SUBFILED value until Field38 ,when the sorting reaches Field38 i want Field38 data elements to remain exactly in same order as it was in the input file.
And after Field38 , from Field39 sort as normal on Fileds and SUBFILED value.
For this i have planned to move Field38's SUBFILED values by say some position right and do your operation.
And after completion of our operation reorient it.
Thank you so much. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Start a new topic and explain better. What do you mean field38 not sorted but fields either side sorted? Do you mean exclude field38 from the sort key?
And when posting pleases read before hitting the Post key - SUBFILED? FILEDS? |
|
Back to top |
|
|
|