%EDITC Built-In Functions in rpgle

%EDITC Function is used to format numeric values with special characters like Asterisk(*),Period(.),Comma(,),Cent sign(¢), Pound sign(£),Dollar sign($), minus sign(-), Credit sign(CR) etc. It can also be used to supress zeros or format number with slash(/) to result in date format.

In Real scenario, we can see many examples where we need to generate reports with amount fields in the form $12,345.67-, $12,345.67CR, '***12345.67-' instead of displaying the amount as -12,345.67 In those report generation program, we can use %EDITC Function and can generate the output as we want.

%EDITC is used in the form %EDITC(numeric : editcode : {*ASTFILL | *CURSYM | currency-symbol})

Here,
  1st parameter is Input numeric value which we want to edit.
  2nd parameter is the editcode option used to generate the required edited string.
  3rd parameter is other format option used to generate the required edited string. 
  3rd parameter is optional parameter. 

Below are IBM i edit codes:

1 to 4
A to D
J to Q
W to Z

Lets see with examples the use of %EDITC.


Example 1–%editc 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 DInput1           S              7P 0 Inz(0123456)                         
0002.00 DInput2           S              7S 0 Inz(-0123456)                        
0003.00 DInput3           S              7P 2 Inz(01234.56)                        
0004.00 DInput4           S              7S 2 Inz(-01234.56)                       
0005.00 DInput5           S              7P 2 Inz(00000.00)                        
0006.00                                                                            
0007.00 DEditcode_1       S             50A                                        
0008.00                                                                            
0009.00 C* Edit code "1" to format numeric value                                   
0010.00 C                                                                          
0011.00 C                   Eval      Editcode_1 = %EDITC(Input1:'1') + ' ' +      
0012.00 C                                          %EDITC(Input2:'1') + ' ' +      
0013.00 C                                          %EDITC(Input3:'1') + ' ' +      
0014.00 C                                          %EDITC(Input4:'1') + ' ' +      
0015.00 C                                          %EDITC(Input5:'1')              
0016.00                                                                            
0017.00 C     Editcode_1    dsply                                                  
0018.00 C                                                                          
0019.00 C                   Seton                                        LR        
        ****************** End of data ********************************************   


Output

DSPLY    123,456   123,456  1,234.56  1,234.56       .00  



Below table shows Output for all editcodes on Input values(0123456,-0123456,01234.56,-01234.56,00000.00)




Below table shows how the Output are formatted by using the editcodes.




Example 2–%editc built-in function in rpgle


Use of 3rd parameter {*ASTFILL | *CURSYM | currency-symbol}

Below are the uses of these param value:

*ASTFill -  When *ASTFill is specified, It fills the leading zeros with asterisks(*) 
*CURSYM - When *CURSYM is specified, the currency symbol is placed in the result just before the first significant digit.
Currency symbol - It is a 1-byte character constant and is evaluated at compile time to produce the output in evaluated symbol.





 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00 DOutput1          S             50A                                        
0002.00 DOutput2          S             50A                                        
0003.00 DOutput3          S             50A                                        
0004.00                                                                            
0005.00 C* Edit code "1" to format numeric value                                   
0006.00 C                                                                          
0007.00 C                   Eval      Output1 = %EDITC(-000123.45:'K':*ASTFILL)    
0008.00 C                   Eval      Output2 = %EDITC(-000123.45:'K':*CURSYM)     
0009.00 C                   Eval      Output3 = %EDITC(-000123.45:'K':'$')         
0010.00                                                                            
0011.00 C     Output1       dsply                                                  
0012.00 C     Output2       dsply                                                  
0013.00 C     Output3       dsply                                                  
0014.00 C                                                                          
0015.00 C                   Seton                                        LR        
        ****************** End of data ******************************************** 


Output

DSPLY  ****123.45-  
DSPLY      $123.45- 
DSPLY      ¢123.45- 


In third output we are getting output in ¢ (Not in $). At compile time the currecy($) changes to currency(¢). Hence it is producing different output.










User Comments:



Subscribe

  Email:



Copyright © www.go4as400.com, 2013-2017. Copyright notice