I would like to know, how we should handle decimal points.
0.896, if i convert this to ZD, how it gets converted, if i view in file aid, it is showing as 8.96, but i need this to be 0.90
, we are giving only total length in the control card, and not the decimal length.
Please advise, how does the sort determines the decimal point.
OK, a simpler question. SORT does not know a single thing about decimal alignment or rounding, you have to do it all yourself.
With a variable number of decimal places present, you are going to end up PARSEing your field, integer part and decimal part. Then stick them together next to each other, then look to do any zero-padding, then the rounding (look at the final digit, if greater than 4 (GE 5) add one to the number excluding the final digit. Then locate your rounded-and-fixed-number-of-decimal-places data to wherever you want finally.
Inserting actual decimal points can be done with the EDIT and a mask. Alignment is just on the length of the field, and the decimal point is at a fixed place in the mask.
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Tue May 10, 2016 10:29 am Post subject:
Magesh_J,
As william pointed out, DFSORT does not differentiate the decimal dot. So if your requirement is to just have 2 decimals , then you need to define the rules for rounding.
if you have the following values what do you do?
Code:
0.838 ROUNDED TO 0.84 OR 0.85 ?
1.009 ROUNDED TO 1.01 OR 1.10 ?
2.994 ROUNDED TO 2.95 OR 3.00 ?
2.996 ROUNDED TO 3.00 OR ???
btw if you have plans of building the parsed values you don't have to store them you can use % to just skip them. Something like this
0.838 ROUNDED TO 0.84
1.009 ROUNDED TO 1.01
2.994 ROUNDED TO 2.99
2.996 ROUNDED TO 3.00
Kolusu wrote:
DFSORT does not differentiate the decimal dot.
I have told that i may get values s9(7)v999. But all my host file variables are s9(7)v99, so I have instructed source team to send only with two decimal points.
If they come with 2 decimals points
I will get values max off -9999999.99, so when i do the parse, i have to give Fix length of 11 and when i convert it to ZD i should give length 9 ?
or what is the length i should give.
If they cant, then i should add +.01 if 3rd byte of decimal is greater than 5 and add none when it is less than or equal to 5, then i can ignore the last byte of the field and then convert it to ZD. But still same question what is the length i should give when i convert it to ZD, The parse with '.' will remove the decimal, so i need to add the decimal point manually or to use the edit STTTTTTT.TT and the convert to ZD ?
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Thu May 12, 2016 6:00 pm Post subject:
Magesh_J wrote:
I have told that i may get values s9(7)v999. But all my host file variables are s9(7)v99, so I have instructed source team to send only with two decimal points.
If they come with 2 decimals points
I will get values max off -9999999.99, so when i do the parse, i have to give Fix length of 11 and when i convert it to ZD i should give length 9 ?
or what is the length i should give.
If they cant, then i should add +.01 if 3rd byte of decimal is greater than 5 and add none when it is less than or equal to 5, then i can ignore the last byte of the field and then convert it to ZD. But still same question what is the length i should give when i convert it to ZD, The parse with '.' will remove the decimal, so i need to add the decimal point manually or to use the edit STTTTTTT.TT and the convert to ZD ?
Please advise.
Thanks
Magesh
Magesh,
You are complicating a simple request. Unless it is a numeric edited field neither COBOL nor DFSORT would care as to where the decimal dot is.
So if you have a 9 field and it contains 123456789 you can read the same data in different ways depending on your Cobol declaration.
So if you have
Code:
N1 PIC S9(1)V9(8). the value 123456789 will be 1.23456789
N2 PIC S9(2)V9(7). the value 123456789 will be 12.3456789
N3 PIC S9(3)V9(6). the value 123456789 will be 123.456789
...
So forget about the intricacies of handling the decimal digit. You only need to be concerned about handling the maximum value in a 9 byte zd field.
From the looks of it you can have 8 digits ( 1 byte sign and 7 byte numeric data for integer portion ) and may have a max 3 digits for decimals.
So those values fit in perfectly into S9(7)V99 as you are rounding the decimals.
Here is the Job which would give you the desired results.
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