View previous topic :: View next topic
|
Author |
Message |
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
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 |
|
|
kratos86
Active User
Joined: 17 Mar 2008 Posts: 148 Location: Anna NGR
|
|
|
|
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 |
|
|
Guest
|
|
|
|
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
|
|
|
|
in order to find records with large salaries (gt 3000),
with FIRST(n), you would need to sort D (descending). |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
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 )
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 |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Quote: |
Is this a mass kidnap-for-ransom plan we are helping with? |
If so, I want my cut |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
vasanthz wrote: |
Quote: |
Is this a mass kidnap-for-ransom plan we are helping with? |
If so, I want my cut |
Sorry, no, it wouldn't fit in seven digits. |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Bill,
Do you have a secret name called like Colonel Jessep? (A Few Good Men)
You want the Ransom?! YOU CANT HANDLE THE RANSOM..!! |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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.
|
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
mmm, That sounds like a legit military disclaimer..
This conversation never happened..
oohh wait.. what? whos that guy with an axe? omg gotta go |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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 |
|
|
|