Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

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
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

RPG (Report Program Generator) FAQ

General

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             
  *                                                
  *                                                
  *                                                
  /FREE   
       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';
       Endif;


       //
       // Convert & Use
       //
       MyNumber =  %DEC(MyAlpha : 4:0);            
       MyNumber = MyNumber + 10 ;
  
       //
       // Convert Back If You Like
       //
       MyAlpha = %CHAR(MyNumber);
  /END-FREE                                        

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

My Archive

Close Box

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close