Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Does FUNCTION NUMVAL work for alphanumeric with negative val

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Venkata Ramayya

New User


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

PostPosted: Fri Mar 20, 2015 10:43 pm    Post subject: Does FUNCTION NUMVAL work for alphanumeric with negative val
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: 331
Location: USA

PostPosted: Fri Mar 20, 2015 11:19 pm    Post subject: Reply to: Does FUNCTION NUMVAL work for alphanumeric with negative val
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: 39
Location: United States

PostPosted: Sat Mar 21, 2015 12:24 am    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Sat Mar 21, 2015 2:45 am    Post subject:
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: 39
Location: United States

PostPosted: Mon Mar 23, 2015 10:28 pm    Post subject:
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

Senior Member


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

PostPosted: Tue Mar 24, 2015 5:01 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Mar 24, 2015 6:00 pm    Post subject: Reply to: Does FUNCTION NUMVAL work for alphanumeric with negative val
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: 331
Location: USA

PostPosted: Tue Mar 24, 2015 6:50 pm    Post subject: Reply to: Does FUNCTION NUMVAL work for alphanumeric with negative val
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: 39
Location: United States

PostPosted: Tue Mar 24, 2015 7:50 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm
No new posts Replace function abdulrafi COBOL Programming 13 Mon Sep 12, 2016 10:12 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us