Sort the output again using sort.

IBM's Sort Product, ICETOOL, ICEMAN and ICEGENER.
Post Reply
Maven JJ
Registered Member
Posts: 14
Joined: Thu May 19, 2016 3:36 pm

Sort the output again using sort.

Post by Maven JJ »

I have a file having state code and some more records in it. I need to find that how many records are there for each state code.The 150-151 colums hold the US state code.

Records in dataset are like this:

Code: Select all

|ST|AGENT:CODE|EFF DATE| 
========================
IL |A |021    |20160128| 
MI |A |002    |20160110| 
CT |A |036    |20160208| 
CT |A |266    |20160117| 
AK |A |723    |20160107| 
MD |A |876    |20160114| 
CA |A |244    |20160102| 
MA |A |499    |20160225| 

So far i have written a sort like this:

Code: Select all

//SYSIN DD * 
INREC FIELDS=(1,224,225:C'000001') 
SORT FIELDS=(150,2,CH,A) 
INCLUDE COND=(150,2,CH,NE,C' ',AND,150,2,CH,NE,C'==') 
SUM FIELDS=(225,6),FORMAT=ZD 
OUTREC FIELDS=(1:150,2,3:C' - ',6:225,6) 
It gives me output

Code: Select all

AK - 000032 
AL - 000321 
AR - 000013 
AZ - 000032 
CA - 000234 
CO - 000128 
The problem is that the output records are sorted in the alphabetical order of the state code, while I wanted to output in the ascending order of the number of occurence (second column in output) , how do I do that?

Can anyone help me out with this please? I think it can be done in a single step instead of writing another step to sort the output again.
User avatar
Magesh_j
Registered Member
Posts: 33
Joined: Sun Sep 04, 2016 8:50 pm

Re: Sort the output again using sort.

Post by Magesh_j »

Can be done without sorting twice, but cant be done in single pass.

To find a count of a state, if it is already in sorted order by state, then you need not require a sort or sumfield

untested code

Code: Select all

OPTION COPY
OUTFIL SECTIONS=(150,2,TRAILER3=(150,2,C' - ',COUNT=(EDIT=(TTTTTT)))),REMOVECC,NODETAIL
And 2nd step

Code: Select all

SORT FIELDS=(6,6,ZD,A)
Regards,
Magesh
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM DFSort, ICETOOL, ICEMAN, ICEGENER.”