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

SORT the input file to keep only 100 record in SORTOUT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Thu May 05, 2011 11:02 am
Reply with quote

Suppose I have 5 million records in my input file. I want to sort the input file and keep the output file only 100 records.

Suppose my input file records are:

Code:

EMP-NO   EMP-Name  sal      desg     comments
0005     Albert       2000  SSE      xxxxxxxxxxxxx
0003     Michael      5000  CEO      xxxxxxxxxxxxx

and so on....

I want to sort the records on the basis whose sal > 3000. Also keeping in mind i want to keep only 100 records in my output file(whether it may be 1st 100 sorted records or last 100 sorted records.. does not matter). because after the SORT i saw i got more records in my output file.
LRECL = 80 and RECFMT = fixed..

Thanks
Back to top
View user's profile Send private message
kratos86

Active User


Joined: 17 Mar 2008
Posts: 148
Location: Anna NGR

PostPosted: Thu May 05, 2011 11:41 am
Reply with quote

If you spend little effort in searching the forum you could have got it.

Anyways, Use the STOPAFT Parameter to limit the number of records in your ouput. If you dont know how to use it, there are couple of threads in the forum which can help you.
Back to top
View user's profile Send private message
Guest







PostPosted: Thu May 05, 2011 11:41 am
Reply with quote

Hi Maxsubrat,
I believe you can use the Subset option to solve your requirement.
Since i am not aware of the length of your individual fields.
I have written a sample sort jcl which you can modify accordingly:
Code:

//IN       DD *                                           
10                                                       
09                                                       
08                                                       
07                                                       
06                                                       
05                                                       
04                                                       
03                                                       
//OUT      DD SYSOUT=*                                   
//TOOLIN   DD *                                           
  SUBSET FROM(IN) TO(OUT) OUTPUT KEEP FIRST(5) USING(CTL1)
/*                                                       
//CTL1CNTL DD *                                           
 SORT FIELDS=(1,2,ZD,A)                                   
/*                                                       


Kindly get back to me if the requirement is not met

Devil13
There is always a better solution.
Back to top
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu May 05, 2011 12:07 pm
Reply with quote

in order to find records with large salaries (gt 3000),
with FIRST(n), you would need to sort D (descending).
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Thu May 05, 2011 1:01 pm
Reply with quote

Hello,
It appears that the Salary field on the input file is not on fixed column position.
It would have been better if the TS gave more information about if the fields are of fixed length.

Assuming that the maximum length of Empname as 42 & Salary length as 10(I wish my salary field length was 7 icon_biggrin.gif )

The below job could be used for the requirement,
Code:
//JS020    EXEC PGM=ICETOOL                                         
//TOOLMSG  DD SYSOUT=*                                             
//DFSMSG   DD SYSOUT=*                                             
//SORTIN   DD DISP=SHR,DSN=WELLS.SORTIN                           
//SORTOUT  DD DSN=WELLS.SORTOUT,DISP=OLD                         
//SYSOUT   DD SYSOUT=*                                             
//TOOLIN   DD *                                                     
  SUBSET FROM(SORTIN) TO(SORTOUT) OUTPUT KEEP FIRST(100) USING(CTL1)
/*                                                                 
//CTL1CNTL   DD *                                                   
  INREC PARSE=(%00=(STARTAFT=C' ',ENDBEFR=C' ',FIXLEN=42),   
               %01=(ENDBEFR=C' ',FIXLEN=10)),               
  OVERLAY=(81:%01,JFY=(SHIFT=RIGHT))                         
  SORT FIELDS=(81,10,ZD,A)                                   
  OUTFIL INCLUDE=(81,10,ZD,GE,3000),BUILD=(1,80)                           
/*                                                                 
//SYSUDUMP DD SYSOUT=*                                             
/*     


Hope it helps.
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Thu May 05, 2011 1:05 pm
Reply with quote

Hi,

why sort 5 million records if only 100 records are needed and it appears it doesn't matter which 100 are selected.

I would try this. You need to adjust the positions as no record layout has been mentioned.



Code:
//S1       EXEC PGM=SORT                             
//SYSOUT   DD SYSOUT=*                               
//SORTIN   DD *                                       
         4000                                         
         1000                                         
         2000                                         
         5000                                         
         3000                                         
//SORTOUT  DD SYSOUT=*                               
//SYSIN    DD *                                       
  OPTION COPY,STOPAFT=2                               
  INCLUDE COND=(10,4,CH,GT,C'3000')                   
/*                                                   


Gerry
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Thu May 05, 2011 1:16 pm
Reply with quote

Or mix Dick and Gerry with vasanthz's code. Only sort those greater than 30,000, descending, and only extract the first hundred (highest).

Is this a mass kidnap-for-ransom plan we are helping with?
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Thu May 05, 2011 2:09 pm
Reply with quote

Quote:
Is this a mass kidnap-for-ransom plan we are helping with?

If so, I want my cut icon_biggrin.gif
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Thu May 05, 2011 2:49 pm
Reply with quote

vasanthz wrote:
Quote:
Is this a mass kidnap-for-ransom plan we are helping with?

If so, I want my cut icon_biggrin.gif


Sorry, no, it wouldn't fit in seven digits.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Thu May 05, 2011 3:20 pm
Reply with quote

Bill,
Do you have a secret name called like Colonel Jessep? (A Few Good Men)
You want the Ransom?! YOU CANT HANDLE THE RANSOM..!! icon_biggrin.gif
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Thu May 05, 2011 3:30 pm
Reply with quote

If I did, and you found out, then something would happen to you, with absolutely no involvement from myself, but by which you would no longer be able to continue breathing.
icon_biggrin.gif
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Thu May 05, 2011 3:50 pm
Reply with quote

mmm, That sounds like a legit military disclaimer..icon_eek.gif
This conversation never happened..
oohh wait.. what? whos that guy with an axe? omg gotta go icon_axe.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu May 05, 2011 8:12 pm
Reply with quote

as usual the code tags are something kind of unknown here!

the whole issue does not make any sense
Quote:
Also keeping in mind i want to keep only 100 records in my output file(whether it may be 1st 100 sorted records or last 100 sorted records.. does not matter).


I guess it would make some difference getting the first 100 records with salaries from 3001 to let's 10000
rather than last 100 records with salaries from 100000 to 345779000
( reverse the first and the last according to the sort order )
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon May 09, 2011 6:48 pm
Reply with quote

To add to Enrico...
Quote:

Suppose I have 5 million records in my input file. I want to sort the input file and keep the output file only 100 records.


How about last key at 100 th record has many occurances?
Eg
Code:

rec001 key 1
rec002 key 1
rec003 key 2
.
.
.
.
.
.
rec099 key 40
rec100 key 40
rec101 key 40
rec102 key 40
rec103 key 40


What about below records....
rec101 key 40
rec102 key 40
rec103 key 40
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts WER247A SORTOUT HAS INCOMPATIBLE LRECL SYNCSORT 2
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
Search our Forums:

Back to Top