IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need only Top 3 occurance of a field


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Dingu

New User


Joined: 06 Jul 2007
Posts: 10
Location: Chentrappinni

PostPosted: Tue Sep 25, 2007 10:43 pm
Reply with quote

Hi,

I have two fields in the File. CustomerID and Value. Both are numeric field. File can contain upto 16 "Value" field for a "CustomerID". My need is to sort descending by the field "Value" and pickup 3 Records for a CustomerID. So the output file will contain,

Code:

CUSTID1 243
CUSTID1 123
CUSTID1 099
CUSTID2 456
CUSTID2 345
CUSTID2 212


Can we have this using normal SORT?
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Sep 25, 2007 11:06 pm
Reply with quote

Here's a DFSORT job that will do what you asked for. I assumed your input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes.

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=...  input file (FB/80)
//SORTOUT DD DSN=...  output file (FB/80)
//SYSIN DD    *
  SORT FIELDS=(1,7,CH,A,9,3,ZD,D)
  OUTREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,7))
  OUTFIL INCLUDE=(81,8,ZD,LE,+3),BUILD=(1,80)
/*
Back to top
View user's profile Send private message
Dingu

New User


Joined: 06 Jul 2007
Posts: 10
Location: Chentrappinni

PostPosted: Fri Sep 28, 2007 9:49 am
Reply with quote

Thank You Frank, It's Working....
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Sat Aug 09, 2008 3:15 am
Reply with quote

If you have z/OS DFSORT V1R5 PTF UK90013 (July, 2008) you can now use the new SELECT FIRST(n) function to do this more easily like this.

Code:

//S1   EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN DD DSN=...  input file
//OUT DD DSN=...  output file
//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(1,7,CH) FIRST(3) USING(CTL1)
/*
//CTL1CNTL DD *
  SORT FIELDS=(1,7,CH,A,9,3,ZD,D)
/*


For complete details on the new FIRST(n) function and the other new functions available with PTF UK90013, see:

Use [URL] BBCode for External Links
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts S0C7 - Field getting overlayed COBOL Programming 2
No new posts Masking variable size field - min 10 ... DFSORT/ICETOOL 4
Search our Forums:

Back to Top