INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site
(Download This Button Today!)
"...The level of expertise is awesome. The nature in which people respond is professional helpful and not the least condescending. I can't say that for most forums..."
Where in the world do Tek-Tips members come from?
Convert Character To Numeric & Visa Versa
Posted: 8 Apr 04
A handy little technique I noted down ages ago allows a conversion from a character field to a numeric field using an RPG IV BIF. Some sites have standard program or routines to do this but if you don't have one this might be handy.
The following code takes an alpha field value and converts it to a number before adding 10 to it just to prove it works. The one draw back to be wary of, is the occurance of alpha fields with all blanks in it. You must perform a condition before the %DEC BIF to make sure blanks are replaced with zeros or the %DEC will runtime fail.
DMyAlpha S 4A
DMyNumber S 4 0
MyAlpha = '1234';
// Check Source For 0's Zeroes
// which in this case is not
// necessary as MyAlpha is
// hard coded to '1234'
If ( MyAlpha = *BLANKS );
MyAlpha = '0000';
// Convert & Use
MyNumber = %DEC(MyAlpha : 4:0);
MyNumber = MyNumber + 10 ;
// Convert Back If You Like
MyAlpha = %CHAR(MyNumber);
I think somebody told me how to do this on a forum ages ago but I still find it so handy I felt it deserved a FAQ.
Back to RPG (Report Program Generator) FAQ Index
Back to RPG (Report Program Generator) Forum
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
- Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close