|
View previous topic :: View next topic
|
| Author |
Message |
siva_pris
New User
Joined: 14 Apr 2006 Posts: 4
|
|
|
|
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 |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
 |
madmartinsonxx
New User

Joined: 10 Dec 2010 Posts: 96 Location: Massachusetts
|
|
|
|
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 |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
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 |
|
 |
madmartinsonxx
New User

Joined: 10 Dec 2010 Posts: 96 Location: Massachusetts
|
|
|
|
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 |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
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 |
|
 |
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
| 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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
madmartinsonxx
New User

Joined: 10 Dec 2010 Posts: 96 Location: Massachusetts
|
|
|
|
| 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 |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| 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 |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
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  |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|