Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
how to convert CHAR format to a NUMERIC?

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

New User


Joined: 13 Jun 2008
Posts: 15
Location: china

PostPosted: Tue Sep 16, 2008 10:25 am    Post subject: how to convert CHAR format to a NUMERIC?
Reply with quote

I want to know how to convert format from CHAR to INTEGER(from X to 9).
please help me. thanks.
Back to top
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Sep 16, 2008 10:29 am    Post subject:
Reply with quote

Use function NUMVAL which returns the numeric value represented by the character string
Back to top
View user's profile Send private message
Young zhang

New User


Joined: 13 Jun 2008
Posts: 15
Location: china

PostPosted: Tue Sep 16, 2008 10:37 am    Post subject:
Reply with quote

example: log-id pic x(12),
log-count pic 9(12).
...
procedure division.
...
(convert from log-id to log-count )
...
(conver form log-count to log-id)
...

so, how to use the commands to solve the two funciton below. please give me a detail expression, thank you.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Sep 16, 2008 10:45 am    Post subject:
Reply with quote

COMPUTE LOG-COUNT = FUNCTION NUMVAL(LOG-ID) and

MOVE LOG-COUNT TO LOG-ID
Back to top
View user's profile Send private message
Young zhang

New User


Joined: 13 Jun 2008
Posts: 15
Location: china

PostPosted: Tue Sep 16, 2008 11:14 am    Post subject:
Reply with quote

ashimer, thank you. I will try it.
Back to top
View user's profile Send private message
saurabhgemini10

New User


Joined: 15 Sep 2008
Posts: 5
Location: India

PostPosted: Tue Sep 16, 2008 11:47 am    Post subject:
Reply with quote

What will happen if the variable is having some alphabets in that., example

COMPUTE COUNT = FUNCTION NUMVAL(suppose that variable is having the value as ABC12)

what will the result ?? value in COUNT
if error then what error??
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 Sep 16, 2008 12:56 pm    Post subject:
Reply with quote

Hi,

Main purpose of the NUMVAL and NUMVAL-C is to convert alphanumeric data items that contain free-format character-representation numbers to numeric form, and process them numerically. For example:
Code:
01  R            Pic x(20)  Value "- 1234.5678".
01  S            Pic x(20)  Value "  $12,345.67CR".
01  Total        Usage is Comp-1.
. . .
Compute Total = Function Numval(R) + Function Numval-C(S)Use NUMVAL-C when the argument includes a currency symbol or comma, or both, as shown in the example.

Check this link for more details:

http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.aix.cbl.doc/rlinfnv.htm
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Sep 16, 2008 7:22 pm    Post subject:
Reply with quote

Hello,

Quote:
What will happen if the variable is having some alphabets in that.,
You need to make sure the field(s) have valid content before you use them as numeric. If you do not ensure valid numbers, at some point the code will most likely abend.
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
No new posts File Aid tool to compare numeric data balaji81_k Compuware & Other Tools 2 Tue Sep 26, 2017 3:35 am
No new posts Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm
No new posts Return a Non Numeric value from REXX Learncoholic CLIST & REXX 3 Fri Sep 01, 2017 8:33 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us