%CHAR Built-In Functions in rpgle

%CHAR function is used to convert numeric, date, time, timestamp or graphic data type into character data type.

It is used as %CHAR(expression{:format}).

For date, time, or timestamp data, the second parameter represents date, time, or timestamp format.

If we don't want the seperator characters in date/time/timestamp, just suffix the format with 0, e.g. Use *iso0 instead of *iso in timestamp to get timestamp without any seperator character.

Example –%char built-in function in rpgle




 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00                                                                                 
0002.00      D timestamp       s               Z                                        
0003.00      D date            s               D                                        
0004.00      D time            s               T                                        
0005.00      D Output          s             40A                                        
0006.00                                                                                 
0007.00       *Find current timestamp,date & time value                                 
0008.00      C                   EVAL      timestamp = %TIMESTAMP()                     
0009.00      C                   EVAL      date = %DATE()                               
0010.00      C                   EVAL      time= %TIME()                                
0011.00      C                                                                          
0012.00       *  *iso = 'yyy-mm-dd-hh.mm.ss.uuuuuu'                                     
0013.00      C                   EVAL      Output   = %char(timestamp:*iso)             
0014.00      C     Output        DSPLY                                                  
0015.00      C                                                                          
0016.00       *  *iso = 'yyy-mm-dd'                                                     
0017.00      C                   EVAL      Output   = %CHAR(date : *iso)                
0018.00      C     Output        DSPLY                                                  
0019.00      C                                                                          
0020.00       *  *mdy = 'mm/dd/yy'                                                      
0021.00      C                   EVAL      Output   = %CHAR(date : *mdy)                
0022.00      C     Output        DSPLY                                                  
0023.00      C                                                                          
0024.00       *  *iso = 'hh.mm.ss'                                                      
0025.00      C                   EVAL      Output   = %CHAR(time : *iso)                
0026.00      C     Output        DSPLY                                                  
0027.00      C                                                                          
0028.00       *  *hms = 'hh:mm:ss'                                                      
0029.00      C                   EVAL      Output   = %CHAR(time : *hms)                
0030.00      C     Output        DSPLY                                                  
0031.00      C                                                                          
0032.00       *  *usa = 'hh:mm AM'                                                      
0033.00      C                   EVAL      Output   = %CHAR(time : *usa)                
0034.00      C     Output        DSPLY                                                  
0035.00      C                                                                          
0036.00                                                                                 
0037.00       *  If we don't want the seperator characters, just suffix the format,     
0038.00       *  with 0, e.g. Use *iso0 instead of *iso                                 
0039.00      C                                                                          
0040.00       *  *iso0 = yyyymmddhhmmssuuuuuu                                           
0041.00      C                   EVAL      Output   = %char(timestamp:*iso0)            
0042.00      C     Output        DSPLY                                                  
0043.00      C                                                                          
0044.00       *  *eur0 = hhmmss                                                         
0045.00      C                   EVAL      Output   = %CHAR(time : *eur0)               
0046.00      C     Output        DSPLY                                                  
0047.00      C                                                                          
0048.00      C                   SETON                                        LR        
        ****************** End of data ********************************************         


Output

DSPLY  2017-11-08-11.50.57.618000         
DSPLY  2017-11-08                         
DSPLY  11/08/17                           
DSPLY  11.50.57                           
DSPLY  11:50:57                           
DSPLY  11:50 AM                           
DSPLY  20171108115057618000               
DSPLY  115057   

 











User Comments:



Subscribe

.  


Copyright © www.go4as400.com, 2013-2023. Copyright notice   Terms of services   Privacy policy