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

Query regarding Sort


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
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
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: 1448
Location: Chicago, IL

PostPosted: Mon Jan 02, 2006 10:16 am
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: 308
Location: Vizag / US

PostPosted: Mon Jan 02, 2006 11:55 am
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 Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Mon Jan 02, 2006 10:11 pm
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:

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 Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Sep 25, 2008 3:30 am
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:

Use [URL] BBCode for External Links
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 Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts RC query -Time column CA Products 3
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
Search our Forums:

Back to Top