IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Does FUNCTION NUMVAL work for alphanumeric with negative val


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Venkata Ramayya

New User


Joined: 03 Dec 2007
Posts: 49
Location: United States

PostPosted: Fri Mar 20, 2015 10:43 pm
Reply with quote

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
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Fri Mar 20, 2015 11:19 pm
Reply with quote

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
View user's profile Send private message
Venkata Ramayya

New User


Joined: 03 Dec 2007
Posts: 49
Location: United States

PostPosted: Sat Mar 21, 2015 12:24 am
Reply with quote

Oh..Ok. Thanks Rahul
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Mar 21, 2015 2:45 am
Reply with quote

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
View user's profile Send private message
Venkata Ramayya

New User


Joined: 03 Dec 2007
Posts: 49
Location: United States

PostPosted: Mon Mar 23, 2015 10:28 pm
Reply with quote

Thanks Robert for identifying the root cause of my problem
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue Mar 24, 2015 5:01 pm
Reply with quote

Quote:
'000000000000-20.87
This is an interesting number, how do you get it as an input to your program?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Mar 24, 2015 6:00 pm
Reply with quote

Anuj,

Perhaps an edited "SIGN LEADING SEPARATE" coupled with an INSPECT TALLYING TALLY FOR LEADING ZEROS UNTIL FIRST '-'.

Just a guess....
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Tue Mar 24, 2015 6:50 pm
Reply with quote

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
View user's profile Send private message
Venkata Ramayya

New User


Joined: 03 Dec 2007
Posts: 49
Location: United States

PostPosted: Tue Mar 24, 2015 7:50 pm
Reply with quote

Yes, Rahul is right.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
Search our Forums:

Back to Top