|
|
| Author |
Message |
Young zhang
New User
Joined: 13 Jun 2008 Posts: 15 Location: china
|
|
|
|
I want to know how to convert format from CHAR to INTEGER(from X to 9).
please help me. thanks. |
|
| Back to top |
|
 |
References
|
|
 |
ashimer
Senior Member
Joined: 13 Feb 2004 Posts: 360 Location: Bangalore
|
|
|
|
| Use function NUMVAL which returns the numeric value represented by the character string |
|
| Back to top |
|
 |
Young zhang
New User
Joined: 13 Jun 2008 Posts: 15 Location: china
|
|
|
|
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 |
|
 |
ashimer
Senior Member
Joined: 13 Feb 2004 Posts: 360 Location: Bangalore
|
|
|
|
COMPUTE LOG-COUNT = FUNCTION NUMVAL(LOG-ID) and
MOVE LOG-COUNT TO LOG-ID |
|
| Back to top |
|
 |
Young zhang
New User
Joined: 13 Jun 2008 Posts: 15 Location: china
|
|
|
|
| ashimer, thank you. I will try it. |
|
| Back to top |
|
 |
saurabhgemini10
New User
Joined: 15 Sep 2008 Posts: 5 Location: India
|
|
|
|
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 |
|
 |
Anuj D.
Global Moderator
Joined: 22 Apr 2006 Posts: 2239 Location: Mumbai, India
|
|
|
|
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 |
|
 |
dick scherrer
Global Moderator
Joined: 23 Nov 2006 Posts: 8768 Location: 221 B Baker St
|
|
|
|
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 |
|
 |
|
|