× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



not too bad of a chore
dvalue s 20a Inz(' - 1A 2A 3A ')
dnumber s 10s 0
/free
number = %Dec(%XLate('A':' ':value):10:0);
*inlr=*on;
return;


Thanks,
Tommy Holden



From:
"Bruce Guetzkow" <bruceg@xxxxxxxxxxxxxxxxxxxxxxx>
To:
<rpg400-l@xxxxxxxxxxxx>
Date:
10/02/2009 07:52 AM
Subject:
Re: RPGLE string to number
Sent by:
rpg400-l-bounces@xxxxxxxxxxxx



Use Scott's example...it is exactly what is needed. Don't bother trying
to extract blanks from your alpha field. This is from the RPGIV (V5R4)
manual on the %DEC BIF:

If the parameter is a character expression, the following rules apply:
- The sign is optional. It can be ?+? or ?-?. It can precede or follow the
numeric data.
- The decimal point is optional. It can be either a period or a comma.
- Blanks are allowed anywhere in the data. For example, ? + 3 ? is a valid
parameter.
- The second and third parameters are required.
- Floating point data, for example ?1.2E6?, is not allowed.
- If invalid numeric data is found, an exception occurs with status code
105.

Check out the third point: blanks are allowed. In fact, they are
ignored. So a value of 'b1b2b3b4b' (b = blank) would translate as 1234. I
know this works...I have production code that uses this (converting Credit
Card numbers entered as '9999 9999 9999 9999' to '9999999999999999').

Now, if you have embedded values other than numeric, blanks, and leading
or trailing sign, that is another issue. If you value is '123A456' and
you want the result to be 123456, you have a bit more work to do.

--Bruce Guetzkow



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.