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 

Reformatting left justified numeric field

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


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Thu Oct 28, 2004 6:23 pm    Post subject: Reformatting left justified numeric field Reply with quote

Hi
Can we use SORT for reformatting the following records?
The input file is
Quote:

111 ABCDE 2.99
111 CDEFG 10.99
222 ABCDE 100.99
333 CDCDE 123456789.99

And the output is
Quote:

111 ABCDE 000000002.99
111 CDEFG 000000010.99
222 ABCDE 000000100.99
333 CDCDE 123456789.99

Assuming LRECL of 80 and the key filed is at position 1 and length 3. The length of the left justified field is 12.( format should be PIC 9(9).99)
_________________
Thank You
-Ace
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Oct 28, 2004 8:40 pm    Post subject: Reply with quote

ace,

There are a couple of ways of justifying the amount fields. The easiest way to achieve the desired results involves 2 passes of the data. we add a seqnum at the end of every record and then split the records into 9 different files depending upon the decimal position. Then you need to concatenate all these 9 files and sort on the seqnum to retain the original order of the records.

The following DFSORT/ICETOOL Jcl will give you the desired results. If your shop has syncsort then change the pgm name to synctool.

Method: 1
Code:

//STEP0100 EXEC  PGM=ICETOOL     
//TOOLMSG  DD SYSOUT=*           
//DFSMSG   DD SYSOUT=*           
//IN       DD *                 
111 AAAAA 1.00                   
222 BBBBB 12.11                 
333 CCCCC 123.22                 
444 DDDDD 1234.33               
555 EEEEE 12345.44               
666 FFFFF 123456.55             
777 GGGGG 1234567.66             
888 HHHHH 12345678.77           
999 IIIII 123456789.88           
//T1       DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//T2       DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//T3       DD DSN=&T3,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//T4       DD DSN=&T4,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//T5       DD DSN=&T5,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//T6       DD DSN=&T6,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//T7       DD DSN=&T7,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//T8       DD DSN=&T8,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//T9       DD DSN=&T9,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//CON      DD DSN=&T1,DISP=OLD,VOL=REF=*.T1               
//         DD DSN=&T2,DISP=OLD,VOL=REF=*.T2               
//         DD DSN=&T3,DISP=OLD,VOL=REF=*.T3               
//         DD DSN=&T4,DISP=OLD,VOL=REF=*.T4               
//         DD DSN=&T5,DISP=OLD,VOL=REF=*.T5               
//         DD DSN=&T6,DISP=OLD,VOL=REF=*.T6               
//         DD DSN=&T7,DISP=OLD,VOL=REF=*.T7               
//         DD DSN=&T8,DISP=OLD,VOL=REF=*.T8               
//         DD DSN=&T9,DISP=OLD,VOL=REF=*.T9               
//OUT      DD SYSOUT=*                                   
//TOOLIN   DD *                                   
   COPY FROM(IN)  USING(CTL1)                     
   SORT FROM(CON) USING(CTL2)                     
//CTL1CNTL DD *                                   
   OUTREC FIELDS=(1,80,SEQNUM,8,ZD)               
   OUTFIL FNAMES=T1,INCLUDE=(12,1,CH,EQ,C'.'),     
   OUTREC=(1,10,8C'0',11,4,23,66)                 
   OUTFIL FNAMES=T2,INCLUDE=(13,1,CH,EQ,C'.'),     
   OUTREC=(1,10,7C'0',11,5,23,66)                 
   OUTFIL FNAMES=T3,INCLUDE=(14,1,CH,EQ,C'.'),     
   OUTREC=(1,10,6C'0',11,6,23,66)                 
   OUTFIL FNAMES=T4,INCLUDE=(15,1,CH,EQ,C'.'),     
   OUTREC=(1,10,5C'0',11,7,23,66)                 
   OUTFIL FNAMES=T5,INCLUDE=(16,1,CH,EQ,C'.'),     
   OUTREC=(1,10,4C'0',11,8,23,66)                 
   OUTFIL FNAMES=T6,INCLUDE=(17,1,CH,EQ,C'.'),     
   OUTREC=(1,10,3C'0',11,9,23,66)                 
   OUTFIL FNAMES=T7,INCLUDE=(18,1,CH,EQ,C'.'),     
   OUTREC=(1,10,2C'0',11,10,23,66)                 
   OUTFIL FNAMES=T8,INCLUDE=(19,1,CH,EQ,C'.'),     
   OUTREC=(1,10,C'0',11,11,23,66)                 
   OUTFIL FNAMES=T9,SAVE,                         
   OUTREC=(1,10,11,12,23,66)                       
//CTL2CNTL DD *                                   
   OPTION EQUALS                                   
   SORT FIELDS=(81,8,ZD,A)                         
   OUTFIL FNAMES=OUT,OUTREC=(1,80)                 
/*


The following method is little complicated but we can achieve the desired results in just 1 pass of the data.

A brief explanation of the job. We will use CHANGE parameter on INREC fields and we pad the zeros negotiating the decimal point. we need 9 change commands on inrec.

we need to take care of NOMATCH cond on the CHANGE parm. so we code a "N" for all the nomatch condition records.

Now once again we use another CHANGE parameter on the OUTREC fields for all the nomatch condition and zero out the value.

We now use a horizontal math function of ADD on the OUTFIL and add all these values and use a EDIT function to acheive the desired results.


Method : 2
Code:

//STEP0100 EXEC  PGM=SORT     
//SYSOUT   DD SYSOUT=*         
//SORTIN   DD *               
111 AAAAA 1.00                 
222 BBBBB 12.11               
333 CCCCC 123.22               
444 DDDDD 1234.33             
555 EEEEE 12345.44             
666 FFFFF 123456.55           
777 GGGGG 1234567.66           
888 HHHHH 12345678.77         
999 IIIII 123456789.88         
//SORTOUT  DD SYSOUT=*         
//SYSIN    DD *                                             
  SORT FIELDS=COPY                                         
  INREC  FIELDS=(1,80,                                     
                 81:12,1,CHANGE=(8,C'.',C'00000000'),       
                                NOMATCH=(C'N'),11,1,13,2, 
                 96:13,1,CHANGE=(7,C'.',C'0000000'),       
                                NOMATCH=(C'N'),11,2,14,2, 
                111:14,1,CHANGE=(6,C'.',C'000000'),         
                                NOMATCH=(C'N'),11,3,15,2, 
                126:15,1,CHANGE=(5,C'.',C'00000'),         
                                NOMATCH=(C'N'),11,4,16,2, 
                141:16,1,CHANGE=(4,C'.',C'0000'),           
                                NOMATCH=(C'N'),11,5,17,2, 
                156:17,1,CHANGE=(3,C'.',C'000'),           
                                NOMATCH=(C'N'),11,6,18,2, 
                171:18,1,CHANGE=(2,C'.',C'00'),             
                                NOMATCH=(C'N'),11,7,19,2, 
                186:19,1,CHANGE=(1,C'.',C'0'),             
                                NOMATCH=(C'N'),11,8,20,2, 
                201:20,1,CHANGE=(1,C'.',C'0'),             
                                NOMATCH=(C'N'),11,9,21,2) 
  OUTREC  FIELDS=(001,80,                             
                  081,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(81,11),X,     
                  096,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(96,11),X,     
                  111,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(111,11),X,     
                  126,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(126,11),X,     
                  141,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(141,11),X,     
                  156,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(156,11),X,     
                  171,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(171,11),X,     
                  186,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(186,11),X,     
                  201,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(202,11))       
  OUTFIL OUTREC=(001,10,                           
                (081,11,ZD,ADD,                   
                 093,11,ZD,ADD,                   
                 105,11,ZD,ADD,                   
                 117,11,ZD,ADD,                   
                 129,11,ZD,ADD,                   
                 141,11,ZD,ADD,                   
                 153,11,ZD,ADD,                   
                 165,11,ZD,ADD,                   
                 177,11,ZD),EDIT=(TTTTTTTTT.TT),   
                 023,58)                           
/*



The outputs from both the jobs is

Code:

111 AAAAA 000000001.00
222 BBBBB 000000012.11
333 CCCCC 000000123.22
444 DDDDD 000001234.33
555 EEEEE 000012345.44
666 FFFFF 000123456.55
777 GGGGG 001234567.66
888 HHHHH 012345678.77
999 IIIII 123456789.88


For a better Understanding of the method 2, run the following job and verify the outputs from each step.

Code:

//STEP0100 EXEC  PGM=SORT     
//SYSOUT   DD SYSOUT=*         
//SORTIN   DD *               
111 AAAAA 1.00                 
222 BBBBB 12.11               
333 CCCCC 123.22               
444 DDDDD 1234.33             
555 EEEEE 12345.44             
666 FFFFF 123456.55           
777 GGGGG 1234567.66           
888 HHHHH 12345678.77         
999 IIIII 123456789.88         
//SORTOUT  DD DSN=STEP0100.OUTPUT,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=SYSDA,
//            SPACE=(CYL,(1,1),RLSE)
//SYSIN    DD *
  SORT FIELDS=COPY                                         
  INREC  FIELDS=(1,80,                                     
                 81:12,1,CHANGE=(8,C'.',C'00000000'),       
                                NOMATCH=(C'N'),11,1,13,2, 
                 96:13,1,CHANGE=(7,C'.',C'0000000'),       
                                NOMATCH=(C'N'),11,2,14,2, 
                111:14,1,CHANGE=(6,C'.',C'000000'),         
                                NOMATCH=(C'N'),11,3,15,2, 
                126:15,1,CHANGE=(5,C'.',C'00000'),         
                                NOMATCH=(C'N'),11,4,16,2, 
                141:16,1,CHANGE=(4,C'.',C'0000'),           
                                NOMATCH=(C'N'),11,5,17,2, 
                156:17,1,CHANGE=(3,C'.',C'000'),           
                                NOMATCH=(C'N'),11,6,18,2, 
                171:18,1,CHANGE=(2,C'.',C'00'),             
                                NOMATCH=(C'N'),11,7,19,2, 
                186:19,1,CHANGE=(1,C'.',C'0'),             
                                NOMATCH=(C'N'),11,8,20,2, 
                201:20,1,CHANGE=(1,C'.',C'0'),             
                                NOMATCH=(C'N'),11,9,21,2) 
//*
//STEP0200 EXEC  PGM=SORT     
//SYSOUT   DD SYSOUT=*         
//SORTIN   DD DSN=STEP0100.OUTPUT,
//            DISP=SHR         
//SORTOUT  DD DSN=STEP0200.OUTPUT,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=SYSDA,
//            SPACE=(CYL,(1,1),RLSE)
//SYSIN    DD *
  SORT FIELDS=COPY
  OUTREC  FIELDS=(001,80,                             
                  081,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(81,11),X,     
                  096,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(96,11),X,     
                  111,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(111,11),X,     
                  126,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(126,11),X,     
                  141,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(141,11),X,     
                  156,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(156,11),X,     
                  171,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(171,11),X,     
                  186,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(186,11),X,     
                  201,1,CHANGE=(11,C'N',C'00000000000'),
                               NOMATCH=(202,11))       
//*
//STEP0300 EXEC PGM=SORT     
//SYSOUT   DD SYSOUT=*         
//SORTIN   DD DSN=STEP0200.OUTPUT,
//            DISP=SHR         
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
  SORT FIELDS=COPY
  OUTFIL OUTREC=(001,10,                           
                (081,11,ZD,ADD,                   
                 093,11,ZD,ADD,                   
                 105,11,ZD,ADD,                   
                 117,11,ZD,ADD,                   
                 129,11,ZD,ADD,                   
                 141,11,ZD,ADD,                   
                 153,11,ZD,ADD,                   
                 165,11,ZD,ADD,                   
                 177,11,ZD),EDIT=(TTTTTTTTT.TT),   
                 023,58)                           
//*


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
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


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

PostPosted: Sun Dec 19, 2004 12:46 pm    Post subject: Reply with quote

With z/OS DFSORT V1R5 PTF UQ95214 or DFSORT R14 PTF UQ95213 (Dec, 2004), you can use DFSORT's new UFF (unsigned free form) format to right justify fields much more easily and efficiently as follows:

Code:

//S2 EXEC  PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN   DD DSN=...  input file
//SORTOUT DD DSN=...   output file
//SYSIN    DD *
  OPTION COPY
  OUTFIL OVERLAY=(11:11,12,UFF,EDIT=(TTTTTTTTT.TT))
/*


This DFSORT UFF job is much easier to code then Method 1 and Method 2 shown above. In a test using 9 million records, this DFSORT UFF job used 76% less cpu time and 37% less elapsed time when compared to Method 2 above.

DFSORT's new UFF (unsigned free form) format can extract up to 31 digits from a field of up to 44 characters. DFSORT's new SFF (signed free form) format can extract a sign and up to 31 digits from a field of up to 44 characters. These new formats can be used in DFSORT's SORT, MERGE,
INCLUDE, OMIT, INREC, OUTREC and OUTFIL statements, and in the ON and BREAK parameters for all of DFSORT's ICETOOL operators.

For complete information on all of the new DFSORT and ICETOOL functions available with these DFSORT PTFs, see:

www.ibm.com/servers/storage/support/software/sort/mvs/pdug/
_________________
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