# SORT to fetch grouped records of particular count

Author Message
N.Nirmal Raj

New User

Joined: 19 Sep 2013
Posts: 7
Location: India

 Posted: Tue Oct 01, 2013 12:09 am Hi , My requirement is to extract records based on grouping key which should be equal to 3 records, should not pick any other records having grouping > 3 or <3. Key Recd a 1 a 1 a 1 a 1 a 1 b 2 b 2 b 2 c 3 c 3 c 3 d 4 d 4 Desired Output b 2 b 2 b 2 c 3 c 3 c 3 I used the following sort card but it fetched records grouped in 1,2 & 3. I need only records grouped in 3. //SYSIN DD * SORT FIELDS=(1,4,BI,A,5,10,D) INREC=(1:31,32:SEQNUM,3,ZD,RESTART=(1,4)) OUTFIL FILES=OUT,BUILD=(1:31,32,ZD,LT,+4) /*
Bill Woodger

Moderator Emeritus

Joined: 09 Mar 2011
Posts: 7312
Location: Inside the Matrix

 Posted: Tue Oct 01, 2013 12:42 am Use JOINKEYS with the same dataset for both input files. Join on your key. In JNF2CNTL use INREC to set up a record (WHEN=INIT and BUILD containng the key and a count of one which is big enough for the greatest number of multiple keys that you can have. Use SUM FIELDS= for the count field. If your input is sorted, specify SORTED,NOSEQCHK on the F1 JOINKEYS. Define a REFORMAT record which has your entire F1 record plus the summed count from F2. Use OPTION COPY for the main task. Use OUTFIL INCLUDE= for the summed count on the reformat being equal to three, and use BUILD= to cut the summed count off the record.
Skolusu

Senior Member

Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

Posted: Tue Oct 01, 2013 1:05 am

N.Nirmal Raj,

Use SELECT operator with EQUAL(3) and you will get the desired results.

for your sample data assuming the key is the first 1 byte then use the following toolin
 Code: //TOOLIN   DD *                                  SELECT FROM(IN) TO(OUT) ON(1,1,CH) EQUAL(3) //*

The output from the above is keys b and c
N.Nirmal Raj

New User

Joined: 19 Sep 2013
Posts: 7
Location: India

 Posted: Tue Oct 01, 2013 10:35 pm Skolusu, Thanks a lot your sort card worked good.
 View Bookmarks All times are GMT + 6 Hours

Search our Forum:

 Topic Forum Replies Similar Topics Inserting records into the empty segm... IMS DB/DC 0 COBOL VS SORT Utility for file format... COBOL Programming 6 Copying data from prev record using SORT SYNCSORT 19 how to get total count from numeric d... SYNCSORT 9 Combining more 4 files with sorted or... DFSORT/ICETOOL 3