Page 1 of 1

Sort retaining group

PostPosted: Wed Sep 28, 2011 3:52 pm
by kvn
Hi,

I need to sort a FB file with LRECL 400. Sorting is to be done first on a 9 byte numeric field at position 10 and then on a 6 byte alpanumeric field at position 304. The file has 3 types of records based on a field at position 39. The field at position 39 can have values 10, 20 or 30. The grouping of the records needs to be maintained after the sort. The 304th byte has value only for type 10 records, for other records it is spaces. For a single type 10 record there can be any number (or none) of type 20 and type 30 records.

Some sample data is given below.
----+----1----+----2----+----3----+----4----....300----+----
111111111000000222AAAAAAA0000000000   10              ZAB123
111111111000000222AAAAAAA0000000000   20             
111111111000000222AAAAAAA0000000000   20             
111111111000000222AAAAAAA0000000000   30             
111111111000000222AAAAAAA0000000000   30             
222222222000000111BBBBBBBB000000000   10              ABC999
222222222000000111BBBBBBBB000000000   20             
222222222000000111BBBBBBBB000000000   30   
222222222000000111CCCCCCCC000000000   10              ABC888
222222222000000111CCCCCCCC000000000   20             
222222222000000111CCCCCCCC000000000   30                       
333333333000000333DDDDDDDD000000000   10              ABCKKK             
333333333000000333DDDDDDDD000000000   30   


After sort the output should be like this:

----+----1----+----2----+----3----+----4----....300----+----
222222222000000111CCCCCCCC000000000   10              ABC888
222222222000000111CCCCCCCC000000000   20             
222222222000000111CCCCCCCC000000000   30                               
222222222000000111BBBBBBBB000000000   10              ABC999
222222222000000111BBBBBBBB000000000   20             
222222222000000111BBBBBBBB000000000   30 
111111111000000222AAAAAAA0000000000   10              ZAB123
111111111000000222AAAAAAA0000000000   20             
111111111000000222AAAAAAA0000000000   20             
111111111000000222AAAAAAA0000000000   30             
111111111000000222AAAAAAA0000000000   30
333333333000000333DDDDDDDD000000000   10              ABCKKK             
333333333000000333DDDDDDDD000000000   30 


Is it possible to do this with syncsort ? Can you please help ?

Regards,
kvn

Re: Sort retaining group

PostPosted: Wed Sep 28, 2011 4:05 pm
by BillyBoyo
So there can be no 20 or 30 without a 10? The "group" can be defined as the presence of a type 10 up to and excluding the next type 10? Do you have a SyncSort manual? I think it can be done, and I'd suspect it is fairly easy. Look in the manual for how to establish a group. Look at any examples there. Once you know the words to search for, hit the internet. If you are still stuck after that, show us what you have found out and someone can probably assist.

Re: Sort retaining group

PostPosted: Wed Sep 28, 2011 5:08 pm
by kvn
Thank you for the reply.

There will not be any type 20 or 30 records without a type 10 record.

Here is the sort card I used for this. But the problem I am facing is that the sort based on the field at 304th position is not happening since there is a sort on the group number.

INREC IFTHEN=(WHEN=GROUP,BEGIN=(39,2,CH,EQ,C'10'),
PUSH=(401:10,9,410:ID=9)),
IFTHEN=(WHEN=(39,2,CH,EQ,C'10'),OVERLAY=(419:C'A',304,6)),
IFTHEN=(WHEN=(39,2,CH,EQ,C'20'),OVERLAY=(419:C'B',304,6)),
IFTHEN=(WHEN=(39,2,CH,EQ,C'30'),OVERLAY=(419:C'C',304,6))
OPTION DYNALLOC
SORT FIELDS=(401,9,CH,A,     
             410,9,ZD,A,     - GROUP NUMBER
             419,1,CH,A,     - A FOR '10', B FOR '20', C FOR '30'
             420,6,CH,A)     
OUTREC BUILD=(1,400)


Regards,
kvn

Re: Sort retaining group

PostPosted: Wed Sep 28, 2011 5:39 pm
by BillyBoyo
Do you need the group-number in the sort itself? I thought the idea of the group would be to get the value available on the 10 record available for all so that you could sort on that.

If you kick the group number out of the sort, put the six byte field as the second sort and then the record-type (don't know why you converted to A, B, C) is that going to get you further?

Also, for the multiple 20s and 30s do you want to preserve the original order? If so, check out EQUALS in the manual.

Re: Sort retaining group

PostPosted: Wed Sep 28, 2011 6:03 pm
by kvn
I tried removing the group number and putting the 6 byte field as the 2nd sort field. But the results are not the way we want it.

----+----1----+----2----+----3----+----4----....300----+----             
222222222000000111BBBBBBBB000000000   20               
222222222000000111CCCCCCCC000000000   20
222222222000000111CCCCCCCC000000000   30
222222222000000111BBBBBBBB000000000   30
222222222000000111CCCCCCCC000000000   10              ABC888
222222222000000111BBBBBBBB000000000   10              ABC999
111111111000000222AAAAAAA0000000000   20
111111111000000222AAAAAAA0000000000   20
111111111000000222AAAAAAA0000000000   30
111111111000000222AAAAAAA0000000000   30
111111111000000222AAAAAAA0000000000   10              ZAB123
333333333000000333DDDDDDDD000000000   30
333333333000000333DDDDDDDD000000000   10              ABCKKK

Re: Sort retaining group

PostPosted: Wed Sep 28, 2011 6:37 pm
by BillyBoyo
You are picking-up the 304,6 from each of the record-types. You need to get the one that you pushed from the type 10, don't you? Ah. Do you see the problem?

Re: Sort retaining group

PostPosted: Wed Sep 28, 2011 9:47 pm
by kvn
Thank you so much for the idea. After changing to sort based on the 6 byte field pushed from type 10 record, it worked perfectly. The output now is in the form shown in the first post.

Thanks again.

Regards,
kvn.

Re: Sort retaining group

PostPosted: Wed Sep 28, 2011 10:01 pm
by BillyBoyo
No problem at all. Glad to hear it is working, and I guess you've learned some useful stuff whilst doing it yourself. Good on you.