View previous topic :: View next topic
|
Author |
Message |
nartcr
New User
Joined: 06 Jun 2007 Posts: 83 Location: anada
|
|
|
|
Hi,
Want to know if this is possible in cobol.
The requirement is:-
Ex 1
Input is 00125.1300
then the output should be 125.13 [ zero suppressed in both the ends ].
Ex2
Input is 130.2300
then the output is 130.23
How can i acheive this output through Cobol program ? Is it possible to use Edit fields here? |
|
Back to top |
|
|
nartcr
New User
Joined: 06 Jun 2007 Posts: 83 Location: anada
|
|
|
|
Any help is appreciated for this. I tried with Z(5).Z(4)
But the zeroes after the decimal is not getting suppressed. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
the picture clauses are used for output usually,
having misaligned decimal points/commas is unpleasant for reading the numbers |
|
Back to top |
|
|
nartcr
New User
Joined: 06 Jun 2007 Posts: 83 Location: anada
|
|
|
|
Thats fine.
First of all,How do we suppress as you said?
I am not able to suppress the leading zeroes as well as trailing zeroes [ together]. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
nartcr
New User
Joined: 06 Jun 2007 Posts: 83 Location: anada
|
|
|
|
I read this thread before posting this. The above thread doesnt talk about trailing zero suppression which is what i require. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Trailing zeroes, unlike leading zeroes, are significant -- they specify the number of digits of accuracy for the decimal value. The only way I know of to remove trailing zeroes is to move the field with the correct number of digits after the decimal specified -- either via a set of IF and MOVE statements or REDEFINES on the variable. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
but if You had used a bit of ingenuity
the forward loop with the reference should have given You a hint
use reference modification in a backward loop
first loop to find out the first non zero digits
then two alternatives
a couple of computations to carry on the offset and a length for a move
or a loop to do the move backwards
( anyway two loops are better than one loop and a flag ) |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
I don't know of a way it can be done using a numeric edited picture clause all by itself, but it could be accomplished using a "move 1 byte at a time" method or with a combination of inspect and reference modification. If the rule is that there will always be only 2 significant digits to the right of the decimal, it can be done using compute and truncation using only a numeric edited picture clause. Your example wasn't specific about that. |
|
Back to top |
|
|
nartcr
New User
Joined: 06 Jun 2007 Posts: 83 Location: anada
|
|
|
|
Thanks for the suggestion. What i had in my mind is same as the reply from enrico-sorichetti. So i am assuning there is no other way around!!! |
|
Back to top |
|
|
Auryn
New User
Joined: 11 Jan 2006 Posts: 83 Location: Lower Saxony (DE)
|
|
|
|
Some years later...
Didn't try yet but probably this may help you:
Code: |
01 division-resault PICTURE 9(7)V9(4).
01 numeric-as-string.
05 numeric-edited PICTURE Z,ZZZ,ZZ9.9999.
******************************************************
MOVE division-result TO numeric-edited
* 0001234.1200 =» _,__1,234.1200
COMPUTE numeric-as-string
= FUNCTION REVERSE (numeric-as-string)
* _,__1,234.1200 =» 0021.432,1__,_
INSPECT numeric-as-string
REPLACING LEADING ZERO
BY SPACE
* 0021.432,1__,_ =» __21.432,1__,_
COMPUTE numeric-as-string
= FUNCTION REVERSE (numeric-as-string)
* __21.432,1__,_ =» _,__1,234.12__
DISPLAY numeric-as-string |
|
|
Back to top |
|
|
Auryn
New User
Joined: 11 Jan 2006 Posts: 83 Location: Lower Saxony (DE)
|
|
|
|
[quote="Auryn"]Some years later...
Didn't try yet but probably this may help you:
Code: |
* (...)
COMPUTE numeric-as-string
= FUNCTION REVERSE (numeric-as-string)
* _,__1,234.1200 =» 0021.432,1__,_
* (...)
COMPUTE numeric-as-string
= FUNCTION REVERSE (numeric-as-string)
* __21.432,1__,_ =» _,__1,234.12__
* (...) |
Grrr, COMPUTE and FUNCTION REVERSE does not work, computing with alphanumeric values is not possible. My fault, sorry for that.
But the phrase
Code: |
MOVE FUNCTION REVERSE (numeric-as-string)
TO numeric-as-string |
works. - And, all together, these statements provide the desired result. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
It is best to reply to currently actiove topics rather than topics that have been dormant for 4+ years.
Additionally, i believe the original request might not have been exactly what was wanted . . .
For example (just guessing the the field is $). suppressing the trailing zeros from 00345.60000 or 023.0000 would be incorrect. If my $ guess is correct. . . |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
You mean my 5-yr old suggestion was of no use? |
|
Back to top |
|
|
|