IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Rounding in SORT card


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
siva_pris

New User


Joined: 14 Apr 2006
Posts: 4

PostPosted: Tue Nov 14, 2006 12:20 pm
Reply with quote

Hi,

I have PD data in the input file. Assume the value is of 3 decimals
I have round the value to 2 decimals and then convert to ZD.
Is it possible using the SORT card.

Regards,
Siva
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Nov 14, 2006 9:14 pm
Reply with quote

Yes, it is possible, but you haven't given enough information to make it clear what you want to do exactly.

Please show an example of the input values in your PD field and what you want for output. Do you want to round up or round down? What is the starting position and length of your PD field? What is the starting position and length you want for your ZD output field? What is the RECFM and LRECL of your input file?
Back to top
View user's profile Send private message
madmartinsonxx

New User


Joined: 10 Dec 2010
Posts: 96
Location: Massachusetts

PostPosted: Thu Sep 22, 2011 11:54 pm
Reply with quote

Hi,
I have an 80 byte input file with 2 sets of numbers that look like:
Code:

              2.00               8.000
            152.28               4.000
            194.59               7.670
              3.00              12.000
            194.59               7.670
              2.00               8.000
            152.28               4.000
            194.59               7.670
              3.00              12.000
            194.59               7.670
              2.00               8.000
            167.31               4.500
            195.52               8.000
             10.20              12.000
            195.52               8.000
              6.80               8.000
            130.13               3.500
            195.52               8.000
              9.78              11.500


Output file is 80 bytes also. My requirement is:
Code:

So for example, 99.505 would round to 99.51, and 99.504 would round to 99.50.


I will just need to place the 3 digit past decimal place rounded number after the second number for comparison purposes / test results.
Thanks. I looked in a couple of the manuals and didn't see anything jump out at me.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Sep 22, 2011 11:58 pm
Reply with quote

madmartinsonxx,

How about answering ALL the questions from Frank?

Frank Yaeger wrote:
What is the starting position and length of your PD field? What is the starting position and length you want for your ZD output field? What is the RECFM and LRECL of your input file?
Back to top
View user's profile Send private message
madmartinsonxx

New User


Joined: 10 Dec 2010
Posts: 96
Location: Massachusetts

PostPosted: Fri Sep 23, 2011 12:10 am
Reply with quote

The starting position and length of the input field I would like to round is:

Code:

starting at 20 for 20 bytes


The starting position and length of the rounded output field would be:

Code:

starting at 42 for 20 bytes


The lrecl and recfm of my input and output file would be:

Code:

DCB=(RECFM=F,LRECL=080,BLKSIZE=080)
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Fri Sep 23, 2011 12:41 am
Reply with quote

madmartinsonxx,

Is your requirement different from OP? The first post mentions about PD fields and you can't



Code:

//STEP0100 EXEC PGM=SORT                               
//SYSOUT   DD SYSOUT=*                                 
//SORTIN   DD *                                         
----+----1----+----2----+----3----+----4----+----5----+-
                                 99.504                 
                                 99.505                 
                                 99.515                 
                                 99.526                 
                                 99.537                 
                                 99.548                 
                                 99.559                 
                                 99.561                 
                                 99.572                 
                                 99.583                 
//SORTOUT  DD SYSOUT=*                                 
//SYSIN    DD *                                         
  SORT FIELDS=COPY                                     
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(42:20,20)),         
  IFTHEN=(WHEN=(61,1,ZD,LT,5),                         
  OVERLAY=(60:60,2,ZD,SUB,61,1,ZD,EDIT=(TT))),         
  IFTHEN=(WHEN=(61,1,ZD,GE,5),                         
  OVERLAY=(60:60,2,ZD,ADD,(+10,SUB,61,1,ZD),EDIT=(TT)))
//*


The output from the above is
Code:

                                 99.504                99.500
                                 99.505                99.510
                                 99.515                99.520
                                 99.526                99.530
                                 99.537                99.540
                                 99.548                99.550
                                 99.559                99.560
                                 99.561                99.560
                                 99.572                99.570
                                 99.583                99.580
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Sep 23, 2011 12:49 am
Reply with quote

madmartinsonxx wrote:
The starting position and length of the input field I would like to round is:

Code:

starting at 20 for 20 bytes


The starting position and length of the rounded output field would be:

Code:

starting at 42 for 20 bytes


The lrecl and recfm of my input and output file would be:

Code:

DCB=(RECFM=F,LRECL=080,BLKSIZE=080)


A 20 byte PD field would contain 39 digits and that would not fit in you 20 byte output field even after rounding and dropping 1 digit. I think you need to go back and review the documentation (if there is any) on the file layout.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Sep 23, 2011 12:51 am
Reply with quote

I think he was tail-gating the original TS/OP.

Madmartin does not have PD, just the "edited" examples he has shown. It was fun to watch him "snap-to" and answer Frank's questions from years before he himself posted!
Back to top
View user's profile Send private message
madmartinsonxx

New User


Joined: 10 Dec 2010
Posts: 96
Location: Massachusetts

PostPosted: Fri Sep 23, 2011 12:54 am
Reply with quote

heh heh. thanks Bill ! I received a hurry up email just prior to posting !what Sir Skolusu did was spot on, in time and right on. And again, as customary, thanks.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Fri Sep 23, 2011 1:09 am
Reply with quote

madmartinsonxx wrote:
I received a hurry up email just prior to posting !what Sir Skolusu did was spot on, in time and right on. And again, as customary, thanks.


Not really. I messed it up. The job would fail if the last 2 decimals are GE 95 ex:

Code:

99.595 
99.596
99.597
99.598
99.599
or

99.995
99.996
99.997
99.998
99.999


Ideally they should be rounded to
Code:

 99.560 
 99.560
 99.560
 99.560
 99.560
100.000
100.000
100.000
100.000
100.000


I will show an updated job later
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Sep 23, 2011 1:34 am
Reply with quote

rounding with all the relative complexities...
half up,half down, half towards 0, half toward inf, half to even, half to odd
seems a good candidate for a DFSORT new builtin icon_biggrin.gif
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Sep 23, 2011 2:00 am
Reply with quote

enrico makes a good point about the rounding.

We have our "terminology". Accountants, actuaries and the likes have their own. Our terminology is "jargon" to them and vice versa.

Unfortunately, sometimes the words are the same, but mean different things in the different terminologies. "Rounding" is a good example. An accountant might ask for "rounding" and you know what "rounding" means to you. It is always worth checking what "rounding" means to them, as they might not mean the sort of stuff that Cobol does.

I remember an article, by Gerry Weinberg, from the '80s, on the problems of Jargon.

A programmer has a rush-job for a data-entry system. He's a thorough guy, so he wonders about doing an "edit" to check the validity of the part-names being loaded. He rings up the user, who is many miles away, and asks if the part names have any "special characters". The user says no. So he codes to reject non-alphanumeric characters in the part names.

System goes live. 90% of the data is rejected. Programmer looks at the data and sees lots of things like 3/4 and 5/8 (as single characters). He rings up the user and says "I thought you said there were no special characters? What are all these fractions?" The use repliers, "Oh, there's nothing special about those, we use them all the time!".

It has been an article well-worth remembering. Saved me embarrasment on a number of occasions.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Fri Sep 23, 2011 2:09 am
Reply with quote

madmartinsonxx,

Use the following DFSORT JCL

Code:

//STEP0100 EXEC PGM=SORT                                       
//SYSOUT   DD SYSOUT=*                                         
//SORTIN   DD *                                               
                                 99.500                       
                                 99.510                       
                                 99.504                       
                                 99.505                       
                                 99.515                       
                                 99.526                       
                                 99.537                       
                                 99.548                       
                                 99.559                       
                                 99.561                       
                                 99.572                       
                                 99.583                       
                                 99.595                       
                                 99.596                       
                                 99.597                       
                                 99.598                       
                                 99.599                       
                                 99.990                       
                                 99.991                       
                                 99.992                       
                                 99.993                       
                                 99.994                       
                                 99.995                       
                                 99.996                       
                                 99.997                       
                                 99.998                       
                                 99.999                       
//SORTOUT  DD SYSOUT=*                                         
//SYSIN    DD *                                               
  SORT FIELDS=COPY                                             
  INREC IFTHEN=(WHEN=(39,1,ZD,LT,5),OVERLAY=(42:20,19,C'0')), 
  IFTHEN=(WHEN=NONE,                                           
  OVERLAY=(42:(20,20,UFF,ADD,+5),SUB,(39,1,ZD,SUB,+5),         
               EDIT=(IIIIIIIIIIIIIIIT.TTT)))                   
//*
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Sep 23, 2011 2:23 am
Reply with quote

Forgot to mention.

If you round to n decimal places, it is, in my experience, normal to only print those n decimal places, not the one after that gets left as zero. You'll end up with "faults" raised for "this column is always zero, why"?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
Search our Forums:

Back to Top