View previous topic :: View next topic
|
Author |
Message |
Amb
New User
Joined: 12 Mar 2010 Posts: 64 Location: India
|
|
|
|
Hi Guys,
I have the following requirement:
I have a variable TEMP which can receive positive or negative value. Irrespective of the value it receives I have to make it positive.
Can any one tell me if we have a function in COBOL to do this?
I require a function only to do this.. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
the COBOL manual will tell if the ABS function is available...
otherwise a good old ...
Code: |
if a <= 0 then a = -a |
( translated to a valid COBOL format ) will be enough |
|
Back to top |
|
|
Mathiv Anan
Active User
Joined: 23 Jul 2008 Posts: 106 Location: USA
|
|
|
|
We can also achieve this by defining 'TEMP' as unsigned so that sign nibble from sending field will be dropped. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
I would suggest that if you use the unsigned way, you comment this var and/or the code using it so it is clear that the intent is to calc abs value. |
|
Back to top |
|
|
|