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 

Space out the duplicate key in Sort

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


Joined: 03 Jun 2004
Posts: 5
Topics: 2

PostPosted: Thu Jun 03, 2004 1:03 am    Post subject: Space out the duplicate key in Sort Reply with quote

input file:
Code:

P01 01 100
P01 02 200
P02 01 300
P02 02 400
P02 03 500
P03 01 600
P03 02 700

I know I can format a report below using outfil with header2 and outrec,

Code:
Part#   Month   Sales

P01        01        100
P01        02        200
P02        01        300
P02        02        400
P02        03        500
P03        01        600
P03        02        700


My question is,
Can I suppress the duplicate part# and have a report like below?

Code:
Part#   Month   Sales

P01        01        100
           02        200
P02        01        300
           02        400
           03        500
P03        01        600
           02        700


Any suggestion?
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 Jun 03, 2004 3:21 am    Post subject: Reply with quote

I did it this way in 3 TOOLIN passes.


Code:

//STEP     EXEC PGM=ICETOOL                                         
//TOOLIN   DD *                                                     
  SELECT FROM(IN01) TO(T1)   ON(1,3,CH) FIRST DISCARD(T2) USING(SEL1)
  SORT   FROM(CON)  TO(T3)   USING(SRT1)                             
  COPY   FROM(T3)   TO(OT01) USING(CPY1)                             
/*                                                                 
//IN01     DD *                                                     
----+----1----+----2----+----3----+----4----+----5----+----6----+---
P01 01 100                                                         
P01 02 200                                                         
P02 01 300                                                         
P02 02 400                                                         
P02 03 500                                                         
P03 01 600                                                         
P03 02 700                                                         
P04 01 800                                                         
/*                                                                 
//T1       DD DSN=&&TEMP0001,
//            DISP=(,PASS)   
//T2       DD DSN=&&TEMP0002,
//            DISP=(,PASS)   
//CON      DD DSN=&&TEMP0001,
//            DISP=(SHR,PASS),
//            VOL=REF=*.T1   
//         DD DSN=&&TEMP0002,
//            DISP=(SHR,PASS),
//            VOL=REF=*.T2   
//T3       DD DSN=&&TEMP0003,
//            DISP=(,PASS)   
//SEL1CNTL DD *               
  OUTFIL FNAMES=T1,           
         OUTREC=(1,80,C'A')   
  OUTFIL FNAMES=T2,           
         OUTREC=(1,80,C'B')   
/*                           
//SRT1CNTL DD *                                           
  SORT   FIELDS=(1,3,CH,A)                                 
  OUTFIL FNAMES=T3,                                       
         HEADER2=(C'Part#',3X,C'Month',3X,C'Sales',80:X,/),
         SECTIONS=(1,3,                                   
                   HEADER3=(1,3,5X,5,2,6X,8,3,80:X)),     
         OUTREC=(8X,5,3,5X,8,3,80:X,81,1),                 
         REMOVECC                                         
/*                                                         
//CPY1CNTL DD *                                           
  OMIT   COND=(1,3,CH,EQ,C' ',&,81,1,CH,EQ,C'A')           
  OUTREC FIELDS=(1,80)                                     
/*                                                       
//OT01     DD SYSOUT=*                                   
//DFSMSG   DD SYSOUT=*                                   
//TOOLMSG  DD SYSOUT=*                                   


The O/P :

Code:

---+----1----+----2--
Part#   Month   Sales
                     
P01     01      100 
        02      200 
P02     01      300 
        02      400 
        03      500 
P03     01      600 
        02      700 
P04     01      800 


The first pass gets you two files. T1 will have first record in a set of duplicates (or, the only record in case of no duplicates) and T2 will have other duplicates. These files are 'tagged' with A and B respectively.

The second pass creates the report. Here, control break is implemented on 1,3,CH. For every break, I am writing the very record that caused the break as the header (HEADER3). HEADER2 gets you the column headers.

If only the second pass were present (as a SORT step) you would have got the HEADER3 record as a data record also. That is why the first pass is needed. The third pass, therefore, keeps only those records which are not in HEADER3 already.

Hope this helps...
_________________
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
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Jun 03, 2004 6:30 am    Post subject: Reply with quote

hypertech,

The below JCL is another alternative for getting the desired results. A brief explanation of the job. I assumed that your input is 80 bytes and of fb recfm

We first format the input record using inrec. We code spaces in the first 3 bytes and we pad the key at the end of the every record. so now the first bytes are spaces for all records and the 81 st position will have the key. Now we sort on the key at 81st position and eliminate dupes. the eliminated dups will be written to CTL1XSUM dataset.now using outrec we write the key in the first position for the first record.

The second sort operator concates these 2 files and once again sorts on the key at 81st position to retain the sequence.


Code:

//STEP0100 EXEC PGM=SYNCTOOL
//TOOLMSG   DD SYSOUT=*           
//DFSMSG    DD SYSOUT=*
//IN        DD *           
P01 01 100               
P01 02 200               
P02 01 300               
P02 02 400               
P02 03 500               
P03 01 600               
P03 02 700               
//T1        DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//CTL1XSUM  DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//CON       DD DSN=&T1,DISP=OLD,VOL=REF=*.T1               
//          DD DSN=&T2,DISP=OLD,VOL=REF=*.CTL1XSUM         
//OUT       DD SYSOUT=*                                   
//TOOLIN    DD *                                           
  SORT FROM(IN)  USING(CTL1)                               
  SORT FROM(CON) USING(CTL2)                               
//CTL1CNTL  DD *                                           
  OPTION EQUALS                                           
  INREC FIELDS=(3X,4,77,1,3)                   
  SORT FIELDS=(81,3,CH,A)                                 
  SUM FIELDS=NONE,XSUM                                     
  OUTFIL FNAMES=T1,OUTREC=(81,3,4,77,81,3)               
//CTL2CNTL  DD *                               
  OPTION EQUALS
  SORT FIELDS=(81,3,CH,A)                                   
  OUTFIL FNAMES=OUT,REMOVECC,                               
          HEADER1=(01:C'PART#',10:C'MONTH',20:C'SALES',/,   
                   01:C'=====',10:C'=====',20:C'=====',80:X),
  OUTREC=(1,4,                                               
          12:05,2,                                           
          22:8,3,80:X)                                       
/*


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Jun 03, 2004 6:48 am    Post subject: Reply with quote

The following Job would also give the desired results. our shop has only syncsort and I cannot test this job. So I would appreciate if anyone with dfsort can test this job and post if it works

Code:

//STEP0100 EXEC PGM=ICETOOL
//TOOLMSG   DD SYSOUT=*           
//DFSMSG    DD SYSOUT=* 
//IN        DD *           
P01 01 100               
P01 02 200               
P02 01 300               
P02 02 400               
P02 03 500               
P03 01 600               
P03 02 700
//T1        DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//T2        DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//CON       DD DSN=&T1,DISP=OLD,VOL=REF=*.T1               
//          DD DSN=&T2,DISP=OLD,VOL=REF=*.T2
//OUT       DD SYSOUT=*           
//TOOLIN    DD *                                           
  SELECT FROM(IN) TO(T1)  ON(1,3,CH) FIRST DISCARD(T2) USING(CTL1)
    SORT FROM(CON) USING(CTL2)   
//CTL1CNTL
  OUTFIL FNAMES=T1,OUTREC=(1,80,1,3)
  OUTFIL FNAMES=T2,OUTREC=(3X,4,77,1,3)
//CTL2CNTL  DD *                               
  OPTION EQUALS
  SORT FIELDS=(81,3,CH,A)                                   
  OUTFIL FNAMES=OUT,REMOVECC,                               
          HEADER1=(01:C'PART#',10:C'MONTH',20:C'SALES',/,   
                   01:C'=====',10:C'=====',20:C'=====',80:X),
  OUTREC=(1,4,                                               
          12:05,2,                                           
          22:8,3,80:X)                                       
/*


Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Cogito-Ergo-Sum
Advanced


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

PostPosted: Thu Jun 03, 2004 9:00 am    Post subject: Reply with quote

Yes, it works fine.

Just one small thing, Kolusu. In the orignal post by hypertech, he mentions HEADER2. So, maybe, you must use HEADER2 instead of HEADER1.
_________________
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
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Jun 03, 2004 6:30 pm    Post subject: Reply with quote

Thanks Cogito for verifying the job.

Even though he mentioned header2, his desired output does not look like he is using the header2.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Cogito-Ergo-Sum
Advanced


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

PostPosted: Thu Jun 03, 2004 6:35 pm    Post subject: Reply with quote

You are welcome, Kolusu.

Another small thing. You do not have a //IN DD * in both the SYNCTOOL and ICETOOL jobs. Wink

Hypertech must tell us, what he desires. Report header or page header.
_________________
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
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Jun 03, 2004 6:46 pm    Post subject: Reply with quote

Thanks cogito,

Edited the posts to add the IN DD * statement. I must have missed in the cut & paste. Well I hate guessing , but can't help it as most of the posters do not provide the right information.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
hypertech
Beginner


Joined: 03 Jun 2004
Posts: 5
Topics: 2

PostPosted: Thu Jun 03, 2004 11:20 pm    Post subject: Reply with quote

Thanks to both Kolusu and Cogito, I got the report to work the way I wanted now.
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: Fri Jun 04, 2004 11:54 am    Post subject: Reply with quote

You are welcome, hypertech, Kolusu.
_________________
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
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