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
 

 

SORT the input file to keep only 100 record in SORTOUT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
maxsubrat

New User


Joined: 27 Feb 2008
Posts: 72
Location: india

PostPosted: Thu May 05, 2011 11:02 am    Post subject: SORT the input file to keep only 100 record in SORTOUT
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    Post subject:
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    Post subject:
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    Post subject:
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: 1445
Location: Azeroth

PostPosted: Thu May 05, 2011 1:01 pm    Post subject:
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: 1703
Location: Australia

PostPosted: Thu May 05, 2011 1:05 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Thu May 05, 2011 1:16 pm    Post subject: Reply to: SORT the input file to keep only 100 record in SOR
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: 1445
Location: Azeroth

PostPosted: Thu May 05, 2011 2:09 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Thu May 05, 2011 2:49 pm    Post subject:
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: 1445
Location: Azeroth

PostPosted: Thu May 05, 2011 3:20 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Thu May 05, 2011 3:30 pm    Post subject: Reply to: SORT the input file to keep only 100 record in SOR
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: 1445
Location: Azeroth

PostPosted: Thu May 05, 2011 3:50 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Thu May 05, 2011 8:12 pm    Post subject: Reply to: SORT the input file to keep only 100 record in SOR
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


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