Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Query regarding Sort

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

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Mon Jan 02, 2006 10:02 am    Post subject: Query regarding Sort
Reply with quote

Hi,

I have got a Flat file.The number of records might vary!!
I need to copy only the last few ( say 10 ) reccords??

a. How do I get the number of records in a file??
b. How do I copy only the last few records??

Thanks for all the information you can provide.

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

priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Mon Jan 02, 2006 10:16 am    Post subject: Re: Query regarding Sort
Reply with quote

Quote:
a. How do I get the number of records in a file??

http://ibmmainframes.com/viewtopic.php?t=1832

Quote:
b. How do I copy only the last few records??

Suppose u want to get last N records,
Add a record key. (of course if it is already not sorted based on a key)
SORT DESC on Key.
Use STOPAFT = N to get results.

Let me know, if you have problem in this.

Regards,

Priyesh.
Back to top
View user's profile Send private message
Gautam512

Active User


Joined: 05 Oct 2005
Posts: 309
Location: Vizag / US

PostPosted: Mon Jan 02, 2006 11:55 am    Post subject: Re: Query regarding Sort
Reply with quote

HI,

This can be done using FileAid.

Try this one if it Works...

Code:

//STEPNAME EXEC PGM=FILEAID
//DD01     DD DSN=INPUT.FILE,DISP=SHR
//DD01O    DD DSN=OUTPUT.FILE1,DISP=OLD
//SYSOUT   DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSLIST  DD SYSOUT=*
//SYSTOTAL DD SYSOUT=*
//SYSIN    DD *
$$DD01  DUMPBACK  OUT=n (Number of records)


Thanks,
Gau
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: Mon Jan 02, 2006 10:11 pm    Post subject:
Reply with quote

You can use the following DFSORT/ICETOOL job to get the last n records for n from 1 to 999. Just substitute the number you want for n in COUNT-n (e.g. COUNT-10).

Code:

//S1 EXEC PGM=ICETOOL
//DFSMSG   DD SYSOUT=*
//TOOLMSG  DD SYSOUT=*
//IN DD DSN=...  input file
//OUT DD DSN=...  output file
//TOOLIN   DD *
COPY FROM(IN) USING(CTL1)
COPY FROM(IN) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
  OUTFIL FNAMES=CTL2CNTL,NODETAIL,REMOVECC,OUTREC=(80X),
         TRAILER1=(2X,C'OPTION SKIPREC=',COUNT-n=(M11,LENGTH=8))
/*
//CTL2CNTL DD DSN=&&OUT,DISP=(,PASS),SPACE=(TRK,(5,5)),UNIT=SYSDA


If n is greater than 999, you can use a DFSORT/ICETOOL job like the one shown at:

http://www.ibm.com/servers/storage/support/software/sort/mvs/tricks/srtmst03.html#t11

The first method uses two COPY operations, whereas the second method uses two SORT operations, so the first method is more efficient.
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: Thu Sep 25, 2008 3:30 am    Post subject:
Reply with quote

Quote:
a. How do I get the number of records in a file??
b. How do I copy only the last 10 records??


You can now do this kind of thing quite easily using new ICETOOL functions available with z/OS DFSORT V1R5 PTF UK90013 (July, 2008). For example:

Code:

//S1   EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN DD DSN=...  input file
//CT DD SYSOUT=*  count of records
//OUT DD SYSOUT=*  last 10 records
//TOOLIN DD *
COUNT FROM(IN) WRITE(CT) DIGITS(8)
SUBSET FROM(IN) TO(OUT) KEEP INPUT LAST(10)
/*


CT will contain the count of records. OUT will contain the last 10 records. For example, if IN has these records:

Code:

RECORD 01   
RECORD 02   
RECORD 03   
RECORD 04   
RECORD 05   
RECORD 06   
RECORD 07   
RECORD 08   
RECORD 09   
RECORD 10   
RECORD 11   
RECORD 12   
RECORD 13   
RECORD 14   
RECORD 15   
RECORD 16   
RECORD 17   
RECORD 18   


CT will have:

Code:

00000018


If appropriate, you can use TEXT('string') to display a text string before the count and/or EDCOUNT(formatting) to format the count differently (e.g. with blanks for leading zeros).

OUT will have:

Code:

RECORD 09   
RECORD 10   
RECORD 11   
RECORD 12   
RECORD 13   
RECORD 14   
RECORD 15   
RECORD 16   
RECORD 17   
RECORD 18   


For complete details on the new WRITE and SUBSET functions 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 -> 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 SORT BUT RETAIN HIGHEST VALUE ON NON-... leondan22 DFSORT/ICETOOL 2 Thu Dec 14, 2017 8:13 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts Extract record for change in combinat... Trinadh DFSORT/ICETOOL 6 Thu Nov 23, 2017 3:32 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us