View previous topic :: View next topic
|
Author |
Message |
Venkata Ramayya
New User
Joined: 03 Dec 2007 Posts: 49 Location: United States
|
|
|
|
I have a negative value '000000000000-20.87' comes in the file and trying to perform NUMVAL operation on X(18) and move it to S9(15)V99. It abends. Can some one help? |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
Numval won't work if you have a '-' in the string.
You may want to use something like this:
Code: |
INSPECT Variable1 TALLYING WS-TALLY FOR ALL '-'
IF WS-TALLY > 0
INSPECT Variable1 REPLACING ALL '-' BY '0'
COMPUTE Variable2 =
FUNCTION NUMVAL(Variable1)
MULTIPLY Variable2 BY -1 GIVING Variable2
ELSE
COMPUTE Variable2 =
FUNCTION NUMVAL(Variable1)
END-IF
|
|
|
Back to top |
|
|
Venkata Ramayya
New User
Joined: 03 Dec 2007 Posts: 49 Location: United States
|
|
|
|
Oh..Ok. Thanks Rahul |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Actually, the syntax diagram for NUMVAL indicates that it handles a + or a - quite nicely. The statement that NUMVAL cannot handle a - is plain wrong -- I've used NUMVAL to convert negative values with a minus sign before without any issues.
Where your problem is, Venkata Ramayya, is that the syntax diagram indicates that the sign must come BEFORE the first digit. If you removed the leading zeroes (via INSPECT, for example), NUMVAL would work quite well on your data. |
|
Back to top |
|
|
Venkata Ramayya
New User
Joined: 03 Dec 2007 Posts: 49 Location: United States
|
|
|
|
Thanks Robert for identifying the root cause of my problem |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Quote: |
'000000000000-20.87 |
This is an interesting number, how do you get it as an input to your program? |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Anuj,
Perhaps an edited "SIGN LEADING SEPARATE" coupled with an INSPECT TALLYING TALLY FOR LEADING ZEROS UNTIL FIRST '-'.
Just a guess.... |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
Quote: |
This is an interesting number, how do you get it as an input to your program? |
I think, such values may come from other databases (e.g Oracle) when the sender try to pad the value with zeroes. |
|
Back to top |
|
|
Venkata Ramayya
New User
Joined: 03 Dec 2007 Posts: 49 Location: United States
|
|
|
|
Yes, Rahul is right. |
|
Back to top |
|
|
|