Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
need help with a tricky sort.

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

New User


Joined: 24 Sep 2008
Posts: 27
Location: Chennai

PostPosted: Fri Jul 12, 2019 12:36 pm    Post subject: need help with a tricky sort.
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: 27
Location: Chennai

PostPosted: Fri Jul 12, 2019 3:02 pm    Post subject: Reply to: need help with a tricky sort.
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: 2201
Location: Hampshire, UK

PostPosted: Fri Jul 12, 2019 3:15 pm    Post subject: Reply to: need help with a tricky sort.
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: 27
Location: Chennai

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

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

Active Member


Joined: 29 Apr 2008
Posts: 509
Location: Maryland

PostPosted: Fri Jul 12, 2019 5:12 pm    Post subject:
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

Active Member


Joined: 29 Apr 2008
Posts: 509
Location: Maryland

PostPosted: Sat Jul 13, 2019 1:26 am    Post subject:
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: 27
Location: Chennai

PostPosted: Sun Jul 14, 2019 11:35 am    Post subject:
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: 2201
Location: Hampshire, UK

PostPosted: Sun Jul 14, 2019 1:28 pm    Post subject: Reply to: need help with a tricky sort.
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.    IBMMAINFRAMES.com Support Forums -> SYNCSORT All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts need assistance on a sort rajiv rengasamy SYNCSORT 11 Fri Jul 26, 2019 8:19 pm
No new posts need help with a tricky sort - Continued rajiv rengasamy SYNCSORT 8 Tue Jul 16, 2019 1:26 pm
No new posts Sort records within a data block rajiv rengasamy DFSORT/ICETOOL 0 Fri Jul 12, 2019 3:25 pm
No new posts To remove the spaces using SORT Card dharmaraok DFSORT/ICETOOL 1 Tue Apr 30, 2019 3:42 pm
No new posts Sort skiprec imagines DFSORT/ICETOOL 7 Thu Feb 28, 2019 1:30 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us