Paul Gilmartin wrote on 07/20/2007 07:13:38 AM:
> There's a thread active in TSO-REXX in which the OP wished
> to extract the last record from a data set. Of course, this
> spawns a school of increasingly byzantine suggestions:
>
> Read into a stem and use the STEM.0th element
>
> Edit Macro
>
> Sort into reverse order and take the first.
>
> Count the legs and divde by four
>
> (I suggested:
>
> cp "//'DATA.SET.NAME(MEMBER)'" /dev/fd/1 | tail -1
>
> ... )
>
> But usually to such questions, Frank chimes in saying
> it's a natural for DFSORT. Is it?
Here's a way to get the last record with DFSORT/ICETOOL in one copy pass.
I assumed the input file has RECFM=FB and LRECL=80, but the job
can be changed appropriately for other attributes. The trick is
to add the same value to every record and use the LAST parameter of
ICETOOL SELECT to get the last record. Normally, SELECT would do a SORT,
but we use SORT FIELDS=COPY to force it to do a COPY instead.
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file (FB/80)
//OUT DD DSN=... output file (FB/80)
//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(81,1,CH) LAST USING(CTL1)
/*
//CTL1CNTL DD *
INREC OVERLAY=(81:C'0')
SORT FIELDS=COPY
OUTFIL FNAMES=OUT,BUILD=(1,80)
/*
Of course, if you already happen to have the same value in all of the
records, this can be simplified even more. For example, if every record
had a blank in position 5, you could use this DFSORT/ICETOOL job:
//S2 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file
//OUT DD DSN=... output file
//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(5,1,CH) LAST USING(CTL1)
/*
//CTL1CNTL DD *
SORT FIELDS=COPY
/*
BTW, here's a clever DFSORT/ICETOOL trick Graham Harris sent me that gets
the last n records of any file:
//LASTN 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 *
* Set n in SKIPREC=n to the number of records needed.
* For example, if you want the last 10 records,
* use SKIPREC=10.
OPTION SKIPREC=n <-- set n to the number of records needed
OUTFIL FNAMES=CTL2CNTL,REMOVECC,NODETAIL,BUILD=(80X),VTOF,
TRAILER1=(3:C'OPTION SKIPREC=',COUNT=(M11,LENGTH=12))
/*
//CTL2CNTL DD DISP=(,PASS),DSN=&&C2,SPACE=(TRK,1),UNIT=SYSDA
Frank Yaeger - DFSORT Development Team (IBM) - [EMAIL PROTECTED]
Specialties: PARSE, JFY, SQZ, ICETOOL, IFTHEN, OVERLAY, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort/
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html