215 pts.
 AS400 - RPGLE, convert character to numeric.
Hi all...!

        Here i give you the code.

DNum_tmp           c              '18745678'

I declared Num_tmp like this and i did some operations then i got
 Res_tmp = '18745678' .

Now the question is i want to convert this char value to decimal that is addtionable. is this clear ?
boz i need to add all these fields.. for that only...

i used like this, but it shows error...
C                    eval      igen = %inth(Res_tmp) 




Surey..
ASKED: Nov 25, 2011  12:35 AM GMT
UPDATED: March 6, 2012  5:59:43 PM GMT
24,710 pts.

Answer Wiki:
You need to use %DEC, not %INT
Last Wiki Answer Submitted:  Nov 25, 2011  2:06 PM (GMT)  by  CharlieBrowne   24,710 pts.
To see other answers submitted to the Answer Wiki View Answer History.
Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _




 

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

 36,400 pts.

 

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.

 36,400 pts.

 

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

 66,765 pts.

 

Hi Tom ..

it’s a runtime error…
A character representation of a numeric value is in error…

this is the error it shows….

Surey..

 215 pts.

 

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..

 215 pts.

 
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

 66,765 pts.

 

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…

 215 pts.

 

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..

 215 pts.

 

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

 36,400 pts.

 

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

 66,765 pts.

 

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

 36,400 pts.

 

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