View previous topic :: View next topic
|
Author |
Message |
ap_mainframes
Active User
Joined: 29 Dec 2005 Posts: 181 Location: Canada
|
|
|
|
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 |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
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 |
|
|
Gautam512
Active User
Joined: 05 Oct 2005 Posts: 308 Location: Vizag / US
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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:
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 |
|
|
|