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

how to convert CHAR format to a NUMERIC?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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
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
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
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

Superior Member


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

PostPosted: Tue Sep 16, 2008 12:56 pm
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:

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

Moderator Emeritus


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

PostPosted: Tue Sep 16, 2008 7:22 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
Search our Forums:

Back to Top