MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to get only 'n' no. of records in o/p file using sort?

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
mls
Beginner


Joined: 10 Nov 2005
Posts: 9
Topics: 5

PostPosted: Tue Jan 06, 2009 3:53 am    Post subject: How to get only 'n' no. of records in o/p file using sort? Reply with quote

Hi,

I have a file with 1000 records. I want to sort them but in the o/p want only 100 records. i.e I want only top 100 sortde records in the o/p. Pls let me know how to do it using Sort?

Thanks,
MLS
Back to top
View user's profile Send private message
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Tue Jan 06, 2009 4:05 am    Post subject: use it. Reply with quote

It should be simple and this is how you do it ! The below is an example only.

Code:

//SORT0001 EXEC PGM=ICEMAN       
//SORTIN   DD *                 
B                               
A                               
D                               
C                               
F                               
E                               
/*                               
//SORTOUT  DD SYSOUT=*           
//SYSOUT   DD SYSOUT=*           
//SYSIN    DD *                 
 SORT FIELDS=(1,1,CH,A),STOPAFT=4
/*                               


HTH.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Tue Jan 06, 2009 11:16 am    Post subject: Reply with quote

mls,

Mfuser's solution will NOT work as STOPAFT parameter is processed before the SORT statement. Check this link which will explain the order of processing in DFSORT.

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ICE1CA20/1.5.4?DT=20060615185603

You need ENDREC on OUTFIL which is processed after the sort . The following DFSORT JCL will give you the desired results. I just showed you an example of keeping the top 5 records after the sort. You can change that number to your desired number of records you want to keep

Code:

//STEP0100 EXEC PGM=ICEMAN   
//SYSOUT   DD SYSOUT=*       
//SORTIN   DD *             
Z                           
E                           
C                           
F                           
B                           
D                           
A                           
//SORTOUT  DD SYSOUT=*       
//SYSIN    DD *             
  SORT FIELDS=(1,1,CH,A)     
  OUTFIL ENDREC=5           
//*


Mfuser,

Please do NOT post solutions without testing.

Thanks
_________________
Kolusu
www.linkedin.com/in/kolusu


Last edited by kolusu on Wed Jan 07, 2009 12:48 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Tue Jan 06, 2009 11:39 am    Post subject: Reply with quote

Just for fun, here's another way to do it with the new SUBSET function of DFSORT's ICETOOL. Note that SUBSET offers a lot of variations on this theme. For complete details, see:

www.ibm.com/systems/support/storage/software/sort/mvs/ugpf/

Code:

//S2   EXEC  PGM=ICETOOL                                           
//TOOLMSG   DD  SYSOUT=*                                           
//DFSMSG    DD  SYSOUT=*                                           
//IN DD *                                                         
Z                                                                 
E                                                                 
C                                                                 
F                                                                 
B                                                                 
D                                                                 
A                                                                 
//OUT DD SYSOUT=*                                                 
//TOOLIN DD *                                                     
SUBSET FROM(IN) TO(OUT) KEEP OUTPUT FIRST(5) USING(CTL1)           
/*                                                                 
//CTL1CNTL DD *                                                   
  SORT FIELDS=(1,1,CH,A)                                           
/*

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Wed Jan 07, 2009 4:35 am    Post subject: Reply with quote

Kolusu, am very sorry Embarassed

It was my data that let me down. I tried my solution with your data and understood the how exactly the STOPAFT works. Thank you.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
mls
Beginner


Joined: 10 Nov 2005
Posts: 9
Topics: 5

PostPosted: Wed Jan 07, 2009 4:51 am    Post subject: Reply with quote

Thanks a lot!
Back to top
View user's profile Send private message
veluvpv
Beginner


Joined: 14 Jul 2008
Posts: 9
Topics: 1

PostPosted: Mon Jan 19, 2009 7:57 am    Post subject: Reply with quote

Hi,

Using SORT we can achieve the result, first step sort it and in second step copy it using STOPAFT...
Code:

//JS010    EXEC PGM=SORT
.
.
//SYSOUT    DD SYSOUT=*           
//SYSIN     DD *                   
   SORT FIELDS=(1,1,CH,A)                       
/*                                 
//JS020    EXEC PGM=SORT
.
.
//SYSOUT    DD SYSOUT=*             
//SYSIN     DD *                   
   SORT FIELDS=COPY,STOPAFT=3       
/*                                 


Regards,
Velu
Back to top
View user's profile Send private message
veluvpv
Beginner


Joined: 14 Jul 2008
Posts: 9
Topics: 1

PostPosted: Mon Jan 19, 2009 8:05 am    Post subject: Reply with quote

Hi,

Please remove the null card // in first step.
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Jan 19, 2009 9:41 am    Post subject: Reply with quote

veluvpv,

good idea. why do it simply in one step when you can do it in two. Rolling Eyes
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Mon Jan 19, 2009 11:17 am    Post subject: Reply with quote

Quote:
first step sort it and in second step copy it using STOPAFT...


veluvpv,

Why on earth would you propose a less efficient solution then the ones already given? How does that help anyone?
_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
veluvpv
Beginner


Joined: 14 Jul 2008
Posts: 9
Topics: 1

PostPosted: Mon Jan 19, 2009 12:57 pm    Post subject: Reply with quote

Frank,
The question is using SORT, but already given solution is not using SORT utility, if their shop doesnot configured to use the ICETOOL or ICEMAN how does that help them??
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Mon Jan 19, 2009 1:05 pm    Post subject: Reply with quote

veluvpv wrote:
Frank,
The question is using SORT, but already given solution is not using SORT utility, if their shop doesnot configured to use the ICETOOL or ICEMAN how does that help them??


veluvpv,

ICEMAN, SORT are two of the program aliases that can be used to invoke the sort product. ICEMAN is the program name for DFSORT. You can invoke DFSORT with PGM=ICEMAN. DFSORT is also shipped with an alias of SORT, so you can use PGM=SORT

DFSORT's official three-character identifier is ICE, so all of the DFSORT modules start with ICE (ICEMAN, ICETOOL, ICEGENER, etc) and all of the DFSORT messages start with ICE (ICExxxs).

other sort products(Syncsort, ca-sort) use (SORT,ICEMAN) as an alias. So when you use PGM=SORT or PGM=ICEMAN, you'll get the sort product installed at your site.

For more information on this read these topics

http://www.mvsforums.com/helpboards/viewtopic.php?t=10067&highlight=iceman+alias

http://www.mvsforums.com/helpboards/viewtopic.php?t=2504&highlight=iceman+alias
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Mon Jan 19, 2009 3:37 pm    Post subject: Reply with quote

Quote:
The question is using SORT, but already given solution is not using SORT utility, if their shop doesnot configured to use the ICETOOL or ICEMAN how does that help them??


Your understanding of sort products is seriously flawed.

There is no SORT utility. There are sort program (utilities) named DFSORT and Syncsort (and CA-Sort). PGM=SORT and PGM=ICEMAN invoke those sort programs (what program did you think PGM=ICEMAN invoked?).

ICETOOL is part of DFSORT (and Syncsort). DFSORT's ICETOOL has been a fully documented, fully supported part of DFSORT since 1991!

A shop does NOT have to be "configured" to use ICETOOL or ICEMAN. If a shop has a license for DFSORT or Syncsort, it can use PGM=ICEMAN or PGM=ICETOOL to invoke those utilities. It would be very rare to find a shop where PGM=ICEMAN wouldn't work and in such a shop PGM=SORT wouldn't work either.

And even if you believed PGM=ICEMAN and PGM=SORT were invoking different products, why wouldn't you just show Kolusu's one pass job with PGM=SORT instead of PGM=ICEMAN, instead of your less efficient two pass job with PGM=SORT?

Had you bothered to try Kolusu's job, you would have found out that it works with YOUR sort product (assuming it's DFSORT or Syncsort).
_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group