Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need only Top 3 occurance of a field

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
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    Post subject: Need only Top 3 occurance of a field
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 Moderator


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

PostPosted: Tue Sep 25, 2007 11:06 pm    Post subject:
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    Post subject: Reply to: Need only Top 3 occurance of a field
Reply with quote

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

DFSORT Moderator


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

PostPosted: Sat Aug 09, 2008 3:15 am    Post subject:
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:

www.ibm.com/systems/support/storage/software/sort/mvs/ugpf/
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts Alter &DATENS field in HEADER1 Angad DFSORT/ICETOOL 4 Mon Apr 24, 2017 11:49 am
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts outrec field outside range Danielle.Filteau SYNCSORT 10 Sat Mar 04, 2017 2:37 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us