Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups 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 -> Mainframe COBOL
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
References
ashimer

Senior Member


Joined: 13 Feb 2004
Posts: 354
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

Senior Member


Joined: 13 Feb 2004
Posts: 354
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 D.

Global Moderator


Joined: 22 Apr 2006
Posts: 2165
Location: Phoenix, AZ

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

Global Moderator


Joined: 23 Nov 2006
Posts: 8652
Location: 221 B Baker St

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
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL All times are GMT + 6 Hours
Page 1 of 1