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: 44
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: 44
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: 8569
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: 44
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: 2504
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: 44
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
This topic is locked: you cannot edit posts or make replies. Missing Negative sign in COBOL COBOL Programming 6
No new posts CA7 Negative dependency JOB=/ CA Products 0
No new posts DB2 - row_number function - Need 1st ... DB2 5
No new posts TWS - ETT File triggering does not wo... IBM Tools 4
No new posts How to Assign a Function key to Mainf... TSO/ISPF 4
Search our Forums:

Back to Top