Page 1 of 1

SORT To take first record of every GROUP

PostPosted: Mon Jun 09, 2014 12:58 pm
by ankushgattani
Hi,

I am trying to code a Sort card to do the following.
My input file is:
AAA1AAA
AAA2AAA
AAA2AAA
AAA3AAA
AAA4AAA
AAA7AAA
AAA9AAA


I want to divide it into three groups
1. Fourth cahracter >= 1 and <3.
2. Fourth cahracter >= 3 and < 6
3. Fourth cahracter >=6

And then I want to take first(or any one, but only one) record of each group.
The input file has thousands of records and i want to copy these 3 reocrds to the output file(one single output file created using MOD in the SORTOUT).
Output file will look like
AAA1AAA
AAA3AAA
AAA7AAA


Is there any option which I can use to divide the input by Logical expressions and then access one record of every group.
I'm not sure if the GROUP function can be applied here.

Thanks

Re: SORT To take first record of every GROUP

PostPosted: Mon Jun 09, 2014 3:00 pm
by BillyBoyo
You have SyncSort, so I don't think you have KEYBEGIN for WHEN=GROUP.

You'll need three WHEN=NONE specifying a SEQNUM with RESTART containing the logical expression (in different locations).

Then a number one in any of those locations is the one you want. OUTFIL INCLUDE= for that, and use BUILD in OUTFIL to return your record to original content.

The sequence numbers need to be long enough to cover the maximum number of records in a group.

Re: SORT To take first record of every GROUP

PostPosted: Thu Jun 12, 2014 11:55 am
by ankushgattani
Hi,

I tried the BEGIN option of WHEN=GROUP to check whether I have it or not, and I have it.
I am using SYNCSORT FOR Z/OS 1.4.1.0R.

I gave BEGIN a try for only the first condition (Fourth cahracter >= 1 and <3.)

It creates individual group for top 3 records every record, because each record satisfies the condition.

 SORT FIELDS=COPY                                               
 INREC IFTHEN=(WHEN=GROUP,BEGIN=(4,1,CH,GE,1,and,4,1,CH,LT,3),PUSH=(8:ID=1))                 


output is like
AAA1AAA1
AAA2AAA2
AAA2AAA3
AAA3AAA
AAA4AAA
AAA7AAA
AAA9AAA


I need the top 3 records to have same identifier, so that i can Apply RECORDS=1 on them to choose first record.
Any suggestions?

Re: SORT To take first record of every GROUP

PostPosted: Fri Jun 13, 2014 11:22 am
by ankushgattani
Was able to do it using IFTHEN condition and BUILD :)

 INREC IFTHEN=(WHEN(4,1,CH,GE,1,and,4,1,CH,LT,3),overlay=(8:C'1')),
           IFTHEN=(WHEN(4,1,CH,GE,3,and,4,1,CH,LT,6),overlay=(8:C'2')),                 
           IFTHEN=(WHEN(4,1,CH,GE,6),overlay=(8:C'3'))                 
 SORT FIELDS=(8,1,CH,A)
 SUM FIELDS=NONE
 OUTREC BUILD=(1,7)