IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

need help with a tricky sort.


IBM Mainframe Forums -> SYNCSORT
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
rajiv rengasamy

New User


Joined: 24 Sep 2008
Posts: 26
Location: Chennai

PostPosted: Fri Jul 12, 2019 12:36 pm
Reply with quote

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
View user's profile Send private message
rajiv rengasamy

New User


Joined: 24 Sep 2008
Posts: 26
Location: Chennai

PostPosted: Fri Jul 12, 2019 3:02 pm
Reply with quote

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
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Jul 12, 2019 3:15 pm
Reply with quote

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
View user's profile Send private message
rajiv rengasamy

New User


Joined: 24 Sep 2008
Posts: 26
Location: Chennai

PostPosted: Fri Jul 12, 2019 3:26 pm
Reply with quote

Thank you Nic,i'll check.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Fri Jul 12, 2019 5:12 pm
Reply with quote

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
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Sat Jul 13, 2019 1:26 am
Reply with quote

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
View user's profile Send private message
rajiv rengasamy

New User


Joined: 24 Sep 2008
Posts: 26
Location: Chennai

PostPosted: Sun Jul 14, 2019 11:35 am
Reply with quote

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
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Sun Jul 14, 2019 1:28 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
Search our Forums:

Back to Top