MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ICETOOL: Extract first and last 5 records per Plan

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
pete
Beginner


Joined: 02 Dec 2002
Posts: 22
Topics: 9
Location: www.state.ct.us

PostPosted: Thu Jan 27, 2005 12:35 pm    Post subject: ICETOOL: Extract first and last 5 records per Plan Reply with quote

I need help with an ICETOOL solution:

Given:
Input;
Code:

123456789012345678901234567890
001A01021825200UAAD2T000001
001A01024113400UAAD2T000002
001A01024726000UAAD2T000003

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.
Back to top
View user's profile Send private message
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Thu Jan 27, 2005 12:58 pm    Post subject: Reply with quote

Quote:
I need to extract the first five records for each plan.
I also need to extract the last 5 records per Plan.


Does that mean, there are always, at a minimum, 10 records per plan? If not, what is to be done?
_________________
ALL opinions are welcome.

Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes.
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Thu Jan 27, 2005 1:17 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pete
Beginner


Joined: 02 Dec 2002
Posts: 22
Topics: 9
Location: www.state.ct.us

PostPosted: Thu Jan 27, 2005 3:34 pm    Post subject: Reply with quote

To Cogito-Ergo-Sum,

The sample of data my customer has given me shows at least 10.

To Frank,

I'm not sure on the PTFs. I'll check with systems programming.

Thank You.
_________________
Regards,
Pete.
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Thu Jan 27, 2005 4:52 pm    Post subject: Reply with quote

Quote:
I'm not sure on the PTFs. I'll check with systems programming.


It's only one PTF. You can check on it yourself by running this job:

Code:

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
//SORTOUT DD DUMMY
//SYSIN DD *
  OPTION COPY
  OUTREC OVERLAY=(5:C'A')
/*


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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pete
Beginner


Joined: 02 Dec 2002
Posts: 22
Topics: 9
Location: www.state.ct.us

PostPosted: Fri Jan 28, 2005 8:40 am    Post subject: Reply with quote

Frank, DFSORT is available, but this customer is running on VSE. Can you help ?

Code:

ILU000I A0 --- CONTROL STATEMENTS/MESSAGES --- DFSORT/VSE 5746-SM3
RELEASE
4.0
            OPTION COPY
                   $
ILU111A B1 INVALID OPTION  KEYWORD
            OUTREC OVERLAY=(5:C'A')
                   $
ILU111A B1 INVALID OUTREC  KEYWORD

_________________
Regards,
Pete.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Jan 28, 2005 8:49 am    Post subject: Reply with quote

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.

Code:

//STEP0100 EXEC PGM=ICETOOL                                         
//TOOLMSG  DD SYSOUT=*                                             
//DFSMSG   DD SYSOUT=*                                             
//IN       DD DSN=YOUR INPUT FILE,                           
//            DISP=SHR                                             
//T1       DD DSN=&T1,DISP=(,PASS),UNIT=SYSDA,SPACE=(CYL,(X,Y),RLSE)
//T2       DD DSN=&T2,DISP=(,PASS),UNIT=SYSDA,SPACE=(CYL,(X,Y),RLSE)
//T3       DD DSN=&T3,DISP=(,PASS),UNIT=SYSDA,SPACE=(CYL,(X,Y),RLSE)
//CON      DD DSN=&T1,DISP=OLD,VOL=REF=*.T1                         
//         DD DSN=&T2,DISP=OLD,VOL=REF=*.T2                         
//FIRST    DD DSN=YOUR FIRST 5 PLAN RECORD FILE,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=SYSDA,
//            SPACE=(CYL,(X,Y),RLSE)     
//LAST     DD DSN=YOUR LAST 5 PLAN RECORD FILE,     
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=SYSDA,
//            SPACE=(CYL,(X,Y),RLSE)   
//TOOLIN   DD *
  SORT FROM(IN) USING(CTL1)
  SPLICE FROM(CON) TO(T3) ON(14,8,CH) WITHALL WITH(1,88) USING(CTL2)
  COPY FROM(T3) USING(CTL3)
//CTL1CNTL DD *
  OPTION EQUALS
  INREC FIELDS=(1,80,            $ TOTAL LRECL                     
                SEQNUM,8,ZD,     $ SEQNUM OF 8 BYTES
                8X,              $ 8 SPACES
                C'00000001')     $ CONSTANT OF '1'
  SORT FIELDS=(14,8,CH,A)        $ SORT ON PLAN NAME
  OUTFIL FNAMES=T1,
  REMOVECC,NODETAIL,
  SECTIONS=(14,8,
  TRAILER3=(1,88,
            MIN=(81,8,ZD,M11,LENGTH=8),
            TOT=(97,8,ZD,M11,LENGTH=8)))
  OUTFIL FNAMES=T2 
//CTL2CNTL DD *
  OPTION EQUALS
  OUTFIL FNAMES=T3,
  OUTREC=(1,80,
         +1,ADD,(81,8,ZD,SUB,89,8,ZD),EDIT=(TTTTTTTT),X,
         (+1,ADD,(81,8,ZD,SUB,89,8,ZD),SUB,97,8,ZD),M25,LENGTH=9)
//CTL3CNTL DD *
  OUTFIL FNAMES=FIRST,INCLUDE=(81,8,ZD,LE,5),
  OUTREC=(1,80)
  OUTFIL FNAMES=LAST,INCLUDE=(90,9,FS,GE,-5),
  OUTREC=(1,80)
/*


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu


Last edited by kolusu on Fri Jan 28, 2005 11:05 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Fri Jan 28, 2005 10:51 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Fri Jan 28, 2005 11:36 am    Post subject: Reply with quote

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:

www.ibm.com/servers/storage/support/software/sort/mvs/pdug/

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:

Code:

XXXXXXXXXXXXXPLAN0001000001                 000013
XXXXXXXXXXXXXPLAN0001000002                 000012
XXXXXXXXXXXXXPLAN0001000003                 000011
XXXXXXXXXXXXXPLAN0001000004                 000010
XXXXXXXXXXXXXPLAN0001000005                 000009
XXXXXXXXXXXXXPLAN0001000006                 000008
XXXXXXXXXXXXXPLAN0001000007                 000007
XXXXXXXXXXXXXPLAN0001000008                 000006
XXXXXXXXXXXXXPLAN0001000009                 000005
XXXXXXXXXXXXXPLAN0001000010                 000004
XXXXXXXXXXXXXPLAN0001000011                 000003
XXXXXXXXXXXXXPLAN0001000012                 000002
XXXXXXXXXXXXXPLAN0001000013                 000001


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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Fri Aug 08, 2008 4:40 pm    Post subject: Reply with quote

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.

Code:

//S1   EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN DD DSN=...  input file
//FIRST DD DSN=...  output file1
//LAST DD DSN=...   output file2
//TOOLIN DD *
SELECT FROM(IN) TO(FIRST) ON(14,8,CH) FIRST(5) USING(CTL1)
SELECT FROM(IN) TO(LAST) ON(14,8,CH) FIRST(5) USING(CTL2)
/*
//CTL1CNTL DD *
  SORT FIELDS=(14,8,CH,A,22,6,ZD,A)
/*
//CTL2CNTL DD *
  SORT FIELDS=(14,8,CH,A,22,6,ZD,D)
/*


For complete details on the new FIRST(n) function and the other new functions available with PTF UK90013, see:

www.ibm.com/systems/support/storage/software/sort/mvs/ugpf/
_________________
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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group