AS400 – RPGLE, convert character to numeric.

2375 pts.
Tags:
AS400 RPGLE
RPG ILE
RPGLE
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..

Answer Wiki

Thanks. We'll let you know when a new response is added.

You need to use %DEC, not %INT

Discuss This Question: 12  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • philpl1jb
    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
    49,435 pointsBadges:
    report
  • philpl1jb
    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.
    49,435 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • Sureyz
    Hi Tom .. it's a runtime error... A character representation of a numeric value is in error... this is the error it shows.... Surey..
    2,375 pointsBadges:
    report
  • Sureyz
    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..
    2,375 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • Sureyz
    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...
    2,375 pointsBadges:
    report
  • Sureyz
    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..
    2,375 pointsBadges:
    report
  • philpl1jb
    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
    49,435 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • philpl1jb
    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
    49,435 pointsBadges:
    report
  • Sureyz
    [...] 9. A member is trying to convert a character to a numeric value. [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following