
As Charlie Brown said
%DEC ( field to be converted : width : number of decimals)
This will throw an error if the value to convert isn’t digits.
Therefore, it should be placed in a monitor block to catch errors.
Phil

Please be more descriptive in the titles of your questions and the selection of keywords.
Title for this might have been
RPGLE, convert character to numeric.

but it shows error…
What error does it show? When does it show — compile or run-time? How are the variables defined? You show the Num_tmp definition, but you don’t show Res_tmp nor igen. If defined properly, there should be no error.
Tom

Hi Tom ..
it’s a runtime error…
A character representation of a numeric value is in error…
this is the error it shows….
Surey..

This is the code..
FMy_dsp cf e workstn
DAlpha c ‘ABCDEFGHIJLKMNOPQRSTUVWXYZ’
DNum_tmp c ‘12594632103109812032011649′
C Z_ADD 0 i_Gen 15 0
C MOVE ‘ ‘ Res_tmp 15
C Alpha:Num_tmp XLATE Gen Res_tmp
C EVAL i_Gen = %dec(Res_tmp:15:0)
C DSPLY i_Gen
Here the Gen is in my Display FIle .. I Declared that usiing +B(15), and changed the field name as Gen ..
Simply, my idea is whatever i gave in that Gen filed (Alphabets) have to converted as Numeric…
Surey..

C Alpha:Num_tmp xlate Gen Res_tmp
Without seeing the value in Gen, there is no way to know what value might end up in Res_tmp. As long as the value can be converted, it should be okay.
C DSPLY i_Gen
I can’t make sense of that statement. The only format that should compile should be:
c dsply i_gen
But I don’t see what good that does.
it’s a runtime error…
When does it show? What statement throws the error?
Tom

yes Tom ..
i mentioned like this only.
C dsply i_Gen
But it shows the error here ..
C eval i_gen = %dec(Res_tmp : 15 : 0)
the error is ..
A character representation of a numeric value is in error..(C G D F)
Surey…

How to give spaces here while typing ..
i gave multiple spaces(using Space bar) but after i pressed Add to Discussion . it show only one space..
Sorry ..
Surey..

Yes
This will throw an error if the value to convert isn’t digits.
Therefore, it should be placed in a monitor block to catch errors.
The value in Res_tmp is the problem.
Do a Dump and check that value.
You’ve converting upper case letters to digits but that insn’t the only thing that can cause errors.
Phil

How to give spaces here while typing ..
HTML usually collapses extra spaces out of normal text. Formatting is required to preserve spaces, or ‘required space’ characters might be used when typing. I’d say that the part of the page that displays the original question automatically preserves spaces, but the comment section does not.
To preserve spaces in comments, you need to use the {code} button to enclose code between start and end tags.
For the error, Phil’s probably right. You need to look at the value in Res_tmp to see what characters are not being translated before using the the %dec() or %int() functions.
Tom

We’re asuming the GEN is a field on the screen format.
That the program does an EXFMT of the screen format before it reaches this point.
Run your program, enter a value in the field press enter
When you get the error select D for dump
Check the spool files for the dump listing.
You will want to search for the values of the fields
GEN and Res_tmp,
Phil
Phil

[...] 9. A member is trying to convert a character to a numeric value. [...]


















