How to convert from numeric to character without suppressing leading zeros in RPGLE

how to convert from numeric to character without suppressing leading zeros in RPGLE
how to convert from numeric to character without suppressing leading zeros in RPGLE, Numeric to character conversion in RPG, %CHAR, %EDITC, edit code X in as400, ibmi, as400,as400andsqltricks
How to convert from numeric to character without suppressing leading zeros in RPGLE

When we perform numeric to character conversion using the %CHAR built-in function in RPGLE, leading zeros are removed from the character resulting in the string as below.

Code for Numeric to Character using %CHAR in RPGLE

RPG Code in Fixed format for converting numeric to the character using %CHAR bif.

     Dcount            S             10P 0 INZ(1)      
     Dchar             S             10a   INZ(' ')    
     C                   EVAL      char = %char(count) 
     C     char          DSPLY                         
     C                   return                                                                     

RPG Code in /Free format for converting numeric to the character using %CHAR bif.

     Dcount            S             10P 0 INZ(1)           
     Dchar             S             10a   INZ(' ')         
      /Free                                                 
       char = %CHAR(count);                                 
       DSPLY char;                                          
       return;                                              
      /End-Free                                                                                                                                                                  

RPG Code in fully Free format for converting numeric to character using %CHAR bif.

**FREE                            
dcl-s count packed(10:0) inz(1);  
dcl-s char char(10) inz(' ');     
char = %CHAR(count);              
DSPLY char;                       
return;                                                                                                  

Program Output

DSPLY  1     
We can use %EDITC built-in function with edit code of 'X' to convert numeric to character without suppressing leading zeros.
RPG Code in Fixed format for how to convert from numeric to character without suppressing leading zeros.
     Dcount            S             10P 0 INZ(1)      
     Dchar             S             10a   INZ(' ')    
     C                   EVAL      char = %EDITC(count:'X') 
     C     char          DSPLY                         
     C                   return                                                                     
RPG Code in /Free format for how to convert from numeric to character without suppressing leading zeros.
     Dcount            S             10P 0 INZ(1)           
     Dchar             S             10a   INZ(' ')         
      /Free                                                 
       char = %EDITC(count:'X');                                 
       DSPLY char;                                          
       return;                                              
      /End-Free                                                                                                                                                                  
RPG Code in fully Free format for how to convert from numeric to character without suppressing leading zeros
**FREE                            
dcl-s count packed(10:0) inz(1);  
dcl-s char char(10) inz(' ');     
char = %EDITC(count:'X');              
DSPLY char;                       
return;                                                                                                  

Program Output

DSPLY  0000000001

Post a Comment

© AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain