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

How to fetch the nth record from a seq file.


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ursvmg

New User


Joined: 24 May 2007
Posts: 52
Location: Chennai

PostPosted: Wed Jun 13, 2007 9:24 am
Reply with quote

I have a sequential file. I want to take out the nth record from that file. Please tell me how it is possible.

Thanks,
Gopal
Back to top
View user's profile Send private message
Devzee

Active Member


Joined: 20 Jan 2007
Posts: 684
Location: Hollywood

PostPosted: Wed Jun 13, 2007 10:11 am
Reply with quote

You can do with SORT.
Back to top
View user's profile Send private message
ursvmg

New User


Joined: 24 May 2007
Posts: 52
Location: Chennai

PostPosted: Wed Jun 13, 2007 10:13 am
Reply with quote

I would be thankfull, if the sample piece of code is given
Back to top
View user's profile Send private message
veerababu_p

New User


Joined: 18 Mar 2006
Posts: 5
Location: mumbai

PostPosted: Wed Jun 13, 2007 10:18 am
Reply with quote

Use

Code:

   SORT FIELDS=COPY
   OUTFIL STARTREC=n,ENDREC=n


veera
Back to top
View user's profile Send private message
ursvmg

New User


Joined: 24 May 2007
Posts: 52
Location: Chennai

PostPosted: Wed Jun 13, 2007 11:38 am
Reply with quote

Thanks Veerababu
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed Jun 13, 2007 1:58 pm
Reply with quote

Gopal,

Try using the below JCL.

Code:
//JOBCARD
//SORTIN   DD  DSN=HLQ.FIRST.FILE,           
//             DISP=SHR                     
//SORTOUT  DD  DSN=HLQ.FIRST.FILE.OUT,       
//             DISP=(NEW,CATLG,CATLG),       
//             DSORG=PS,                     
//             RECFM=FB,                     
//             DATACLAS=LARGE,               
//             UNIT=SYSDA                   
//SORTWK01 DD  UNIT=SYSDA,SPACE=(CYL,(20,5))
//SYSIN    DD  *                             
  OPTION COPY                               
  OUTFIL FNAMES=SORTOUT,STARTREC=3,ENDREC=3 
/*                                           
//SORTMSG  DD  SYSOUT=*                     
//SYSOUT   DD  SYSOUT=*                     
//SYSPRINT DD  SYSOUT=*                     
//SYSUDUMP DD  SYSOUT=*                     
//CEEDUMP  DD  SYSOUT=*                     
//*                                         


where HLQ.FIRST.FILE is
Code:
111 $$$$$
222 AAAAA
444 FFFFF
555 GGGGG
888 CCCCC

& I want only 3rd record of input (444 FFFFF) in the output.
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: Wed Jun 13, 2007 9:02 pm
Reply with quote

Anuj,

1) Since you're doing a COPY you shouldn't use a //SORTWKnn DD.
2) You don't need //SORTMSG, //SYSPRINT or //CEEDUMP.
3) You don't need FNAMES=SORTOUT since that's the default.
4) You don't need to specify RECFM=FB or DSORG=PS for SORTOUT since DFSORT will automatically set the attributes.

So a better version of your job would be:

Code:

//JOBCARD
//SORTIN   DD  DSN=HLQ.FIRST.FILE,           
//             DISP=SHR                     
//SORTOUT  DD  DSN=HLQ.FIRST.FILE.OUT,       
//             DISP=(NEW,CATLG,CATLG),       
//             DATACLAS=LARGE,               
//             UNIT=SYSDA                   
//SYSIN    DD  *                             
  OPTION COPY                               
  OUTFIL STARTREC=3,ENDREC=3 
/*                                           
//SYSOUT   DD  SYSOUT=*                     
//SYSUDUMP DD  SYSOUT=*                     
//*       


However, if would be more efficient to use:

Code:

//SYSIN DD *
    OPTION COPY,SKIPREC=2,STOPAFT=1
/*


which reads and skips the first two records, reads and writes the third record and stops without reading the rest of the records, whereas STARTREC=3,ENDREC=3 reads every record but only copies the third record.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed Jun 27, 2007 7:10 pm
Reply with quote

Frank,

Thanks for the suggestions, you are a good teacher. icon_smile.gif
Thanks again for providing one rather efficient solution.
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 FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top