tags:

views:

128

answers:

1

hi all

I have a file having some number of records and I want to copy only first and last 10 records into another file.

Can anybody tell how to write jcl, using sort, icetool, ect.

+1  A: 

You can use ICETOOL to copy a subset of your input file.

Here's the JCL to copy the first and last 10 records into another file. I'm assuming fixed length records of 80 bytes each.

You'll also have to change the JOB card to fit with your mainframe shop's requirements.

//EXAMP    JOB A400,PROGRAMMER
//STEP1    EXEC PGM=ICETOOL
//SYSOUT   DD SYSOUT=*
//SORTIN   DD DSN=INPUT,DISP=SHR
//T1       DD DSN=&&T1,DISP=(,PASS),UNIT=VIO 
//T2       DD DSN=&&T2,DISP=(,PASS),UNIT=VIO 
//T3       DD DSN=&&T3,DISP=(,PASS),UNIT=VIO
//SORTOUT  DD DSN=OUTPUT,DISP=(NEW,CATLG),UNIT=SYSDA,
//            SPACE=(CYL,(5,1))
//SYSIN    DD * 
  COPY FROM(IN) USING(CTL1)                                     
  COPY FROM(T1) USING(CTL2)                                     
  COPY FROM(T1) USING(CTL3)
  COPY FROM(T2,T3) USING(CTL4)
/* 
//CTL1CNTL DD *
  OUTFIL FNAMES=T1,OUTREC=(1,80,SEQNUM,8,ZD)
/*
//CTL2CNTL DD *
  OUTFIL FNAMES=T2,ENDREC=10
/*
//CTL3CNTL DD *
  SORT FIELDS=(81,8,BI,D)                                       
  OUTFIL FNAMES=T3,ENDREC=10 
/*
//CTL4CNTL DD *
  SORT FIELDS=(81,8,BI,A)                                       
  OUTFIL FNAMES=SORTOUT,OUTREC=(1,80)
//

The first set of control cards (CTL1CNTL) adds a sequence number to the input records.

The second set of control cards (CTL2CNTL) gets the first 10 input records.

The third set of control cards (CTL3CNTL) sorts the input records in reverse order, and gets the first 10 (which would be the last 10) records.

The fourth set of control cards (CTL4CNTL) sorts the extracted records in the correct order and removes the sequence numbers added by the first set of control cards.

Here's IBM's DFSORT Application Programming Guide for more information.

Gilbert Le Blanc
You should add a bit more explanation here. You assuming the input records are 80 bytes each. You add a sequence number to the file giving T1. Grab the first 10 records of T1 giving T2. Sort T1 into reverse order using your sequence number. Grab the first (last) 10 records of T1 giving T3. Merge T2 and T3, sort and drop the sequence numbers giving OUTPUT. The net result is the first and last 10 records of the original input are now in OUTPUT. Without this sort of explanation it might be difficult for a beginner to figure out what you are doing. Neat solution though!
NealB
@NealB: Thanks. I added the explanations. I actually had the assumption that the input records were 80 bytes, but removed it before I submitted the answer.
Gilbert Le Blanc