Ü  %CHAR

·         It converts date, time, timestamp, or numeric expression to character data type.

 

 

Example –%char built-in function in rpgle

 

  I.     Conversion from TIMESTAMP format to character string.


0072.00  * CALCULATE THE TIME FOR THE CURRENT SYSTEM DATE
0073.00 C                   EVAL      TIMESTP=%TIMESTAMP()
0074.00 C                   EVAL      TIME_IS=%TIMESTAMP()
0075.00 C                   EVAL      TIME_ISO=%char(TIME_IS:*iso0)
0076.00 C                   EVAL      CURRYEAR=%dec(%SUBST(TIMe_ISO:1:4):4:0)
0077.00 C                   EVAL      CURRMONTH=%dec(%SUBST(TIMe_ISO:5:2):2:0)
0078.00 C                   EVAL      CURRDAY=%dec(%SUBST(TIMe_ISO:7:2):2:0)

 

OUTPUT

 

TIME_IS = '2012-05-18-07.11.00.926000'             
TIME_ISO = '20120518071100926000'
CURRYEAR=2012
CURRMONTH=05
CURRDAY=18

 

 

 

II.     Conversion of packed decimal to alphanumeric type

 

 

PARTYD = Physical file used

 


Columns . . . :    1  71           Browse                         AMIT/QDDSSRC
SEU==>                                                                  PARTYD
FMT PF .....A..........T.Name++++++RLen++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
0001.00
0002.00      A          R REC2
0004.00      A            PNAME         10A
0005.00      A            PNUM          12A
0006.00      A            PADDR         10A
0007.00      A            OPNDD          2P 0
0008.00      A            OPNMM          2P 0
0009.00      A            OPNYY          4P 0
0010.00      A            OPNSTS         1P 0
0011.00      A          K PNUM
****************** End of data ****************************************

 

In the program below, we are converting OPNDD, OPNMM, OPNYY packed decimal into character DD, MM, YY.

 


Columns . . . :    6  76           Browse                        AMIT/QRPGLESRC
 SEU==>                                                               EDTRPGCCC
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+.
        *************** Beginning of data *************************************
0001.00  *                                                                     
0001.01 HOPTION(*NODEBUGIO)                                                    
0001.02 FPARTYD    UF A E           K DISK 
0014.00 DOPN              DS                                                   
0015.00 DYY                       1      4A                                    
0016.00 DFILLER1                  5      5A   INZ('-')                         
0017.00 DMM                       6      7A                      
0018.00 DFILLER2                  8      8A   INZ('-')                         
0019.00 DDD                       9     10A                                    
 
0018.01 C     S_PNUM        CHAIN     REC2                               90    
0018.02 C                   IF        *IN90=*OFF                               
0018.06 C                   EVAL      DD=%CHAR(OPNDD)                          
0018.07 C                   EVAL      MM=%CHAR(OPNMM)                          
0018.08 C                   EVAL      YY=%CHAR(OPNYY)                          
0018.11 C                   ENDIF

 

OUTPUT

If OPNYY =2012, OPNMM=12, OPNDD=10

Then, OPN=2012-12-10

 





User Comments:





Copyright © Go4as400.com, 2013-2017. Copyright notice