Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Wed Jul 21, 2004 10:17 am Post subject:
You can use a DFSORT/ICETOOL job like the one below to do what you asked for. I assumed that your input data set has RECFM=FB and LRECL=80, but the job can be changed appropriately for different attributes.
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
1000012 goa
1000012 tanjore
1000012 Trichy
1000013 karur
1000013 pune
1000013 trisur
/*
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//CON DD DSN=*.T1,VOL=REF=*.T1,DISP=(OLD,PASS)
// DD DSN=*.T2,VOL=REF=*.T2,DISP=(OLD,PASS)
//OUT DD SYSOUT=*
//TOOLIN DD *
* IN->T1: Get first record with each key and reformat it
* as follows with a copy of the key in 81-87:
* |sb|key|data|key|
* IN->T2: Get second and subsequent records with each key
* and reformat them as follows with a copy of the key
* in 81-87:
* |data.......|key|
SELECT FROM(IN) TO(T1) DISCARD(T2) ON(1,7,CH) FIRST USING(CTL1)
* T1/T2->OUT: Sort on key in 81-87 and then remove it.
SORT FROM(CON) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
OUTFIL FNAMES=T1,OUTREC=(C'sb',1,20,81:1,7)
OUTFIL FNAMES=T2,OUTREC=(9,20,81:1,7)
/*
//CTL2CNTL DD *
OPTION EQUALS
SORT FIELDS=(81,7,CH,A)
OUTREC FIELDS=(1,80)
/*
_________________ Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Mon Dec 20, 2004 7:50 pm Post subject:
With z/OS DFSORT V1R5 PTF UQ95214 or DFSORT R14 PTF UQ95213 Dec, 2004), you can use DFSORT's IFTHEN and RESTART parameters to do this more easily and efficiently as follows:
Code:
//S2 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD *
1000012 goa
1000012 tanjore
1000012 Trichy
1000013 karur
1000013 pune
1000013 trisur
//SORTOUT DD DSN=... output file
//SYSIN DD *
OPTION EQUALS
* Sort on positions 1-7.
SORT FIELDS=(1,7,CH,A)
* Add a seqnum to the end of each record. Restart the
* seqnum at 1 each time positions 1-7 changes.
OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,7))),
* If the seqnum is 1, reformat the record as follows:
* |sb|key|data|
IFTHEN=(WHEN=(81,8,ZD,EQ,+1),BUILD=(C'sb',1,20,80:X)),
* If the seqnum is not 1, reformat the record as follows:
* |data.......|
IFTHEN=(WHEN=NONE,BUILD=(9,20))
/*
This DFSORT job only takes one SORT pass whereas the DFSORT/ICETOOL job I showed above takes two SORT passes.
SEQNUM,8,ZD,RESTART=(1,7) restarts the seqnum at 1 each time the RESTART field changes, e.g.
That allows us to use IFTHEN to reformat the 00000001 records differently from the other records in only one pass. Note that with the IFTHEN/RESTART solution, we could use copy instead of sort if the records are already in order by the key.
For complete information on all of the new DFSORT and ICETOOL functions available with these DFSORT PTFs, see:
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum