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 

Is this possible via sort?

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


Joined: 25 Aug 2003
Posts: 73
Topics: 29

PostPosted: Wed Mar 17, 2004 3:22 am    Post subject: Is this possible via sort? Reply with quote

My input file contains the following data:

Input File:
-------------------------

2002XXX100200300...
2003XXX100300200...
2004XXX100100500...
2002YYY100200300...
2003YYY100200300...
Etc.
Output file should look like this:
------------------------------------

2001XXX000000000...
2002XXX100200300...
2003XXX100300200...
2004XXX100100500...
2001YYY000000000...
2002YYY100200300...
2003YYY100200300...
2004YYY000000000...

Requirement:

1. For all XXX (or YYY) my output file should contain 4 records with years as 2001,2002,2003 and 2004.
2. When 2001 (or 2002,2003,2004) do not exist in the input file load the output file with 2001 (or 2002,2003,2004) + XXX (or YYY depending on the record) and the rest of the cols as zeros.
3. Output file should be sorted on Col 2 (XXX etc.) followed by Col 1. (2001 etc.)

Thanks in Advance..

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


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

PostPosted: Wed Mar 17, 2004 10:19 am    Post subject: Reply with quote

Relaxing,

The following DFSORT/ICETOOL job will give you the desired results. If you have syncsort at your shop then change the pgm name to synctool.I assumed that your input file is 80 bytes in length and is of FB Recfm.

A brief explanation of the Job. We first take the input and split each record into 5 records ,the first record being as is and the next corresponding to the years 2001 thru 2004. We also add a constant(1 thru 5) at the end of every record. The parm '/' is used to split the record in a new line.

The second sort operator takes in the above created dataset and sorts on the key (5,3) and the constants at the end of the record(81,1). By doing so we make sure that we have the orginal record as the first record for each key and year.

The third sort operator takes in the above sorted file and eliminates the duplicates leaving the desired output.

Code:

//STEP0100  EXEC  PGM=ICETOOL                                 
//TOOLMSG   DD SYSOUT=*                                       
//DFSMSG    DD SYSOUT=*                                       
//IN        DD *                                             
2002XXX100200300                                             
2003XXX100300200                                             
2004XXX100100500                                             
2002YYY100200300                                             
2003YYY100200300                                             
2001ZZZ100200300                                             
//T1        DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)   
//T2        DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)   
//OUT       DD DSN=YOUR OUTPUT FILE,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(CYL,(X,Y),RLSE)
//TOOLIN    DD *                                             
 COPY FROM(IN) USING(CTL1)                                   
 SORT FROM(T1) USING(CTL2)                                   
 SORT FROM(T2) USING(CTL3)                                   
//CTL1CNTL  DD *                                             
  OUTFIL FNAMES=T1,                                           
  OUTREC=(1,80,C'1',/,                                       
          C'2001',5,3,73C'0',C'2',/,                         
          C'2002',5,3,73C'0',C'3',/,                         
          C'2003',5,3,73C'0',C'4',/,                         
          C'2004',5,3,73C'0',C'5')                           
//CTL2CNTL  DD *                                             
  SORT FIELDS=(5,3,CH,A,81,1,CH,A)                           
  OUTFIL FNAMES=T2                                           
//CTL3CNTL  DD *   
  OPTION EQUALS                                           
  SORT FIELDS=(5,3,CH,A,1,4,CH,A)                             
  SUM FIELDS=NONE                                             
  OUTFIL FNAMES=OUT,OUTREC=(1,80)
/*


The output from this job is :
Code:

2001XXX000000000000000000000000000000000000000000000000000000000000000000000000
2002XXX100200300                                                               
2003XXX100300200                                                               
2004XXX100100500                                                               
2001YYY000000000000000000000000000000000000000000000000000000000000000000000000
2002YYY100200300                                                               
2003YYY100200300                                                               
2004YYY000000000000000000000000000000000000000000000000000000000000000000000000
2001ZZZ100200300                                                               
2002ZZZ000000000000000000000000000000000000000000000000000000000000000000000000
2003ZZZ000000000000000000000000000000000000000000000000000000000000000000000000
2004ZZZ000000000000000000000000000000000000000000000000000000000000000000000000


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
relaxing
Beginner


Joined: 25 Aug 2003
Posts: 73
Topics: 29

PostPosted: Wed Mar 17, 2004 10:58 am    Post subject: Reply with quote

Thanks Kolusu. I shall try this. It is like going back to school and meeting your magic teacher who knows everything (and in a more elegant way) and is unselfish to share it.
Back to top
View user's profile Send private message
relaxing
Beginner


Joined: 25 Aug 2003
Posts: 73
Topics: 29

PostPosted: Wed Mar 17, 2004 11:55 am    Post subject: Reply with quote

Hi Kolusu/Ravi

I adjusted the job to meet my LRECL/specifications etc.
I was a bit surprised when my job failed with the following message:

Code:
RECORD TYPE IS F - DATA STARTS IN POSITION 1                     
123 BYTE FIXED RECORD LENGTH IS NOT EQUAL TO 80 BYTE LRECL FOR OUT
END OF DFSORT                                                     


I then allocated my file with 123 length and FB and the job went through ok.
Code:
//OUT       DD DSN=MY.FILE, 
//            SPACE=(CYL,(5,5)),             
//            RECFM=FB,                       
//            LRECL=123,                     
//            DISP=(NEW,CATLG,CATLG)         


I guess the automatic allocation is 80 FB unless Record Length is specified.

Regards,
Relaxing
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: Wed Mar 17, 2004 12:19 pm    Post subject: Reply with quote

relaxing wrote
Quote:
I guess the automatic allocation is 80 FB unless Record Length is specified.


No. If the output data set already has an LRECL (e.g. OLD data set) or you specify the LRECL on the DD, then DFSORT does NOT override that LRECL. If the output data set does not already have an LRECL and you don't specify the LRECL on the DD, then DFSORT sets the output LRECL to the length of the reformatted record (e.g. OUTFIL OUTREC length).

You said you adjusted the job, but you don't show what you changed. However, the error message (ICE222A) indicates that you reformatted the record to 123 bytes with OUTFIL OUTREC, but you have LRECL=80 for the OUT data set.

When you post messages, please include the message number. Note that you can look up all of the DFSORT messages online using Lookat:

http://www.ibm.com/servers/s390/os390/bkserv/lookat/lookat.html

Just type in ICE222A and you'll get the full documentation for this DFSORT message.
_________________
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
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Mar 17, 2004 12:28 pm    Post subject: Reply with quote

Relaxing,

For sort you never have to code the dcb parameters. They are automatically calculated.so get rid of LRECL & RECFM parameters.If you notice my job , it does not have the DCB parameter. Since your input file is of recfm F, I am overriding that parameter to FB in the very first step itself. Now you output file is of RECFM FB.

The following JCL is tailored for your requirement.

Code:

//STEP0100  EXEC  PGM=ICETOOL                                   
//TOOLMSG   DD SYSOUT=*                                         
//DFSMSG    DD SYSOUT=*                                         
//IN        DD DSN=YOUR TEST.INPUT,                         
//             DISP=SHR                                         
//T1        DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE),RECFM=FB     
//T2        DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE) 
//OUT       DD DSN=YOUR OUTPUT FILE,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(CYL,(X,Y),RLSE)     
//TOOLIN    DD *                                               
 COPY FROM(IN) USING(CTL1)                                     
 SORT FROM(T1) USING(CTL2)                                     
 SORT FROM(T2) USING(CTL3)                                     
//CTL1CNTL  DD *                                               
  OUTFIL FNAMES=T1,                                             
  OUTREC=(1,123,C'1',/,                                         
          C'2001',5,3,116C'0',C'2',/,                           
          C'2002',5,3,116C'0',C'3',/,                           
          C'2003',5,3,116C'0',C'4',/,                           
          C'2004',5,3,116C'0',C'5')                             
//CTL2CNTL  DD *                                               
  SORT FIELDS=(5,3,CH,A,124,1,CH,A)                             
  OUTFIL FNAMES=T2                                             
//CTL3CNTL  DD *                                               
  OPTION EQUALS                                                 
  SORT FIELDS=(5,3,CH,A,1,4,CH,A)                               
  SUM FIELDS=NONE                                               
  OUTFIL FNAMES=OUT,OUTREC=(1,123)                             
/*


Hope this helps...

Cheers

Kolusu

PS: Next time you post , please post all the details like RECFM, LRECL along with a sample input and desired output. This will reduce the guesswork.
_________________
Kolusu
www.linkedin.com/in/kolusu
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