The input file is in order by PLAN (pos 14 for 8 ) and SEQUENCE ( pos 22 for 6 ). Sequence refers to PLAN not the file ( each Plan has a 1,2,3,4,5, etc. Sequence). There are hundreds of Plans ( one illustrated above is 00UAAD2T ).
I need to extract the first five records for each plan.
I also need to extract the last 5 records per Plan.
I searched for solutions, but I did not find any. Anyone have any ideas ?
Your help is appreciated. _________________ Regards,
Pete.
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Thu Jan 27, 2005 1:17 pm Post subject:
Pete,
Well, since you have sequence numbers starting at 1 for each plan, the following INCLUDE statement will extract the first 5 records for each plan:
Code:
INCLUDE COND=(22,6,ZD,LE,5)
We could use a trick with the new SEQNUM,m,f,RESTART=(p,m) parameter of z/OS DFSORT V1R5 PTF UQ95214 or DFSORT R14 PTF UQ95213 (Dec, 2004) to get the last five records for each Plan. Do you have the new PTF installed or can you get it installed? _________________ 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
If you get an ICE104A error message for the OVERLAY parameter, you have DFSORT, but don't have the PTF. _________________ 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: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Fri Jan 28, 2005 8:49 am Post subject:
Pete,
The following DFSORT/ICETOOL jcl will give you the desired results. Frank might be able to show you another way to do this with the new ptf which involves less amount of code. If your shop has syncsort then change the pgm name to synctool. Note that you need SYNCSORT FOR Z/OS 1.1 and higher for this jcl to work with syncsort.
I assumed that your input file length is 80 bytes and is FB dataset. You sort key is at pos 14 for 8 bytes.
A brief explanation of the Job.
The first copy operator creates 2 files.
T1 just contains the starting seqnum of every unique plan number along with the total no: of plans for each plan.
T2 is just a copy of input
Now we concatenate these 2 files and splice them so that all the records in the input file are having a seqnum as well as the total subtracted from the seqnum of each record.
ex input: I have 2 plans aaa and bbb. aaa has a total of 5 plans and bbb has a total of 2 records.
Code:
aaa
aaa
aaa
aaa
aaa
bbb
bbb
Now the splice operator puts a seqnum to the plans as well as the total subtracted from the seqnum of each record.
i.e
Code:
plan seq relative count
aaa 01 01-total no; of plans(5) = -4
aaa 02 01-total no; of plans(5) = -3
aaa 03 01-total no; of plans(5) = -2
aaa 04 01-total no; of plans(5) = -1
aaa 05 01-total no; of plans(5) = 0
bbb 01 01-total no; of plans(2) = -1
bbb 02 01-total no; of plans(2) = -0
Now the last copy operator evaluates the seqnum for picking the first 5 records for every plan and evaluate the relative count to pick the last 5 records.
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Fri Jan 28, 2005 10:51 am Post subject:
Quote:
DFSORT is available, but this customer is running on VSE. Can you help ?
Not really. DFSORT/VSE is really quite limited in comparison to DFSORT/MVS. _________________ 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: Fri Jan 28, 2005 11:36 am Post subject:
Well, this won't do the VSE customer any good, but here's how you can do this with DFSORT/ICETOOL using the new RESTART parameter.
Since you already have a sequence field for each plan value, we can use that to get the first 5 records for each plan.
To get the last records 5 records for each plan, we can use the new RESTART=(p,m) parameter of SEQNUM. You need z/OS DFSORT PTF UQ95214 or DFSORT R14 PTF UQ95213 (Dec, 2004) to use RESTART. For complete details on all of the new DFSORT and ICETOOL functions available with this PTF, see:
First we sort descending on the sequence field, and add a new seqnum to set 1 for the last record, 2 for the next to last record, etc. We use the new RESTART=(p,m) parameter of SEQNUM to start the seqnum over again at 1 each time the plan changes. At this point, each plan will have n-1 for the sequence field and 1-n for the seqnum field.
Next we sort again by sequence ascending to get the records back in their original order. At this point, each plan will have 1-n for the sequence field and n-1 for the seqnum field. For example, the records for PLAN0001 will
look like this:
Finally, we use an INCLUDE for the sequence field to get the first 5 records for each plan (1-5), and an INCLUDE for the seqnum field to get the last 5 records for each plan (1-5).
Here's the DFSORT/ICETOOL job:
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
XXXXXXXXXXXXXPLAN0002000001
XXXXXXXXXXXXXPLAN0002000002
XXXXXXXXXXXXXPLAN0002000003
XXXXXXXXXXXXXPLAN0002000004
XXXXXXXXXXXXXPLAN0002000005
XXXXXXXXXXXXXPLAN0002000006
XXXXXXXXXXXXXPLAN0002000007
XXXXXXXXXXXXXPLAN0002000008
XXXXXXXXXXXXXPLAN0002000009
XXXXXXXXXXXXXPLAN0002000010
XXXXXXXXXXXXXPLAN0002000011
XXXXXXXXXXXXXPLAN0002000012
XXXXXXXXXXXXXPLAN0003000001
XXXXXXXXXXXXXPLAN0003000002
XXXXXXXXXXXXXPLAN0003000003
XXXXXXXXXXXXXPLAN0003000004
XXXXXXXXXXXXXPLAN0003000005
XXXXXXXXXXXXXPLAN0003000006
XXXXXXXXXXXXXPLAN0003000007
XXXXXXXXXXXXXPLAN0003000008
XXXXXXXXXXXXXPLAN0003000009
XXXXXXXXXXXXXPLAN0003000010
XXXXXXXXXXXXXPLAN0001000001
XXXXXXXXXXXXXPLAN0001000002
XXXXXXXXXXXXXPLAN0001000003
XXXXXXXXXXXXXPLAN0001000004
XXXXXXXXXXXXXPLAN0001000005
XXXXXXXXXXXXXPLAN0001000006
XXXXXXXXXXXXXPLAN0001000007
XXXXXXXXXXXXXPLAN0001000008
XXXXXXXXXXXXXPLAN0001000009
XXXXXXXXXXXXXPLAN0001000010
XXXXXXXXXXXXXPLAN0001000011
XXXXXXXXXXXXXPLAN0001000012
XXXXXXXXXXXXXPLAN0001000013
/*
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//FIRST DD SYSOUT=*
//LAST DD SYSOUT=*
//TOOLIN DD *
SORT FROM(IN) TO(T1) USING(CTL1)
SORT FROM(T1) USING(CTL2)
//CTL1CNTL DD *
* Sort by plan number ascending and sequence descending.
OPTION EQUALS
SORT FIELDS=(14,8,CH,A,22,6,ZD,D)
* Add seqnum 1, 2, 3, ... in 81-86 for each plan (RESTART).
OUTREC OVERLAY=(81:SEQNUM,6,ZD,RESTART=(14,8))
/*
//CTL2CNTL DD *
* Sort by plan number ascending and sequence ascending.
OPTION EQUALS
SORT FIELDS=(14,8,CH,A,22,6,ZD,A)
* FIRST -> records with sequence from 1-5.
OUTFIL FNAMES=FIRST,INCLUDE=(22,6,ZD,LE,+5),
OUTREC=(1,80)
* LAST -> records with seqnum from 1-5.
OUTFIL FNAMES=LAST,INCLUDE=(81,6,ZD,LE,+5),
OUTREC=(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: Fri Aug 08, 2008 4:40 pm Post subject:
If you have z/OS DFSORT V1R5 PTF UK90013 (July, 2008) you can now use the new SELECT FIRST(n) function to do this more easily like this. Note that in CTL1CNTL we sort by sequence ascending and in CTL2CNTL we sort by sequence descending.
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