%EDITW Built-In Functions in rpgle

%EDITW Function is used to format numeric values with special characters like Asterisk(*),Period(.),Comma(,),Cent sign(¢), Dollar sign($), minus sign(-), Credit sign(CR), Percentage(%) etc. It can also be used to 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 %EDITW Function and can generate the output as we want.

%EDITW is used in the form %EDITC(numeric : editword)

Here,
  1st parameter is Input numeric value which we want to edit.
  2nd parameter is the editword option used to generate the required edited string.


Example-1: Use %EDITW to format the number with comma(,) and decimal(.)


After formatting numbers with %EDITW, comma(,) & decimal point(.) appears in the Output in the same relative position, as they were in Input value. e.g. Input number 123456.78 with EDITW 'XXX,XX,X.XX'(X=blank) will be converted into '123,45,6.78'. See more in below example.




 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00 D Input1          S              5P 2 Inz(123.45)                          
0002.00 D Input2          S              9P 2 Inz(1234567.89)                      
0003.00 D Input3          S              8P 0 Inz(25052017)                        
0004.00 D                                                                          
0005.00 D Output1         S             50A                                        
0006.00 D Output2         S             50A                                        
0007.00 D Output3         S             50A                                        
0008.00                                                                            
0009.00 C                                                                          
0010.00 C* Below %editw param is in the format 'X,XX.XX'                           
0011.00 C                   Eval      Output1    = %editw(Input1:' ,  .  ')        
0012.00 C*                                                                         
0013.00 C* Below %editw param is in the format 'X,XXX,XXX.XX'                      
0014.00 C                   Eval      Output2    = %editw(Input2:' ,   ,   .  ')   
0015.00 C*                                                                         
0016.00 C* Below %editw param is in the format 'XXXXX.XXXX'                        
0017.00 C                   Eval      Output3    = %editw(Input3:'  .  .    ')     
0018.00                                                                            
0019.00 C     Output1       DSPLY                                                  
0020.00 C     Output2       DSPLY                                                  
0021.00 C     Output3       DSPLY                                                  
0022.00 C                                                                          
0023.00 C                   Seton                                        LR        
        ****************** End of data ********************************************


Output

DSPLY  1,23.45             
DSPLY  1,234,567.89        
DSPLY  25.05.2017    


Example-2: Use %EDITW to format number with constant values


Any character other than the very first zero,comma, blank, negative sign (-),"CR" will be treated as a constant. Also in the Output string, it will be in the same relative position as it was in the Input. e.g. 'XWXX,bXb,b.bYb' with the number 123456.78 will be converted to '1W23,4X5,6.7Y8' (b=blank) (W X Y are considered expansion area)




 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00 D Input1          S              4P 0 Inz(1105)                            
0002.00 D Input2          S              8P 0 Inz(25052017)                        
0003.00 D Input3          S              5P 0 Inz(12345)                           
0004.00 D Input4          S              5P 0 Inz(12345)                           
0005.00 D Input5          S              5S 0 Inz(-12345)                          
0006.00 D Input6          S              5S 0 Inz(-12345)                          
0007.00 D                                                                          
0008.00 D Output1         S             50A                                        
0009.00 D Output2         S             50A                                        
0010.00 D Output3         S             50A                                        
0011.00 D Output4         S             50A                                        
0012.00 D Output5         S             50A                                        
0013.00 D Output6         S             50A                                        
0014.00                                                                            
0015.00 C                                                                          
0016.00 C* Below %editw param is in the format 'XX.XXXAM'                          
0017.00 C                   Eval      Output1    = %editw(Input1:'  .   AM')       
0018.00 C*                                                                         
0019.00 C* Below %editw param is in the format 'XX/XX/XXXX'                        
0020.00 C                   Eval      Output2   = %editw(Input2:'  /  /    ')      
0021.00 C*                                                                         
0022.00 C* Below %editw param is in the format 'XXX.XX$'                           
0023.00 C                   Eval      Output3   = %editw(Input3:'   .  $')         
0024.00 C*                                                                         
0025.00 C* Below %editw param is in the format 'XXX.XXCR'                          
0026.00 C                   Eval      Output4    = %editw(Input4:'   .  CR')       
0027.00 C*                                                                         
0028.00 C* Below %editw param is in the format 'XXX.XXCR'                          
0029.00 C                   Eval      Output5    = %editw(Input5:'   .  CR')       
0030.00 C*                                                                         
0031.00 C* Below %editw param is in the format 'XXX.XX-'                           
0032.00 C                   Eval      Output6    = %editw(Input6:'   .  -')        
0033.00                                                                            
0034.00 C     Output1       DSPLY                                                  
0035.00 C     Output2       DSPLY                                                  
0036.00 C     Output3       DSPLY                                                  
0037.00 C     Output4       DSPLY                                                  
0038.00 C     Output5       DSPLY                                                  
0039.00 C     Output6       DSPLY                                                  
0040.00 C                                                                          
0041.00 C                   Seton                                        LR        
        ****************** End of data ********************************************


Output

DSPLY   1.105AM           
DSPLY  25/05/2017         
DSPLY  123.45$            
DSPLY  123.45             
DSPLY  123.45CR           
DSPLY  123.45-    


**Note: In above output, for Output3 we don't get "CR" at the end. The reason, we already stated in the beginning of this example. As stated, characters other than the very first zero,comma, blank, negative sign (-),"CR" will be treated as a constant. Hence, we don't get "CR" at the end fo output. To get "CR" or "-" sign at the end, the number must be -ve number. We used this in the Output4 and Output5.


Example-3: Use %EDITW to format number with additional zeros


As stated earlier, characters other than the very first zero,comma, blank, negative sign (-),"CR" will be treated as a constant. Here if the zeros that we are using are not the first zero, then all other zeros will act as a constant. In other words, if more than 1 zero is entered, then the subsequent zeros are treated as constants. The very first zero becomes the last position that becomes zero suppressed. i.e. Number(00012) with edit word parameter '0XXX' results into




 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00 D Input1          S              5P 0 Inz(00012)                           
0002.00 D Input2          S              5P 0 Inz(00012)                           
0003.00 D Input3          S              8P 0 Inz(05052017)                        
0004.00 D Input4          S              5P 0 Inz(01234)                           
0005.00 D Input5          S              5P 0 Inz(01234)                           
0006.00 D Input6          S              5P 0 Inz(01234)                           
0007.00 D Input7          S              5P 0 Inz(01234)                           
0008.00                                                                            
0009.00 D Output1         S             50A                                        
0010.00 D Output2         S             50A                                        
0011.00 D Output3         S             50A                                        
0012.00 D Output4         S             50A                                        
0013.00 D Output5         S             50A                                        
0014.00 D Output6         S             50A                                        
0015.00 D Output7         S             50A                                        
0016.00                                                                            
0017.00 C*                                                                         
0018.00 C* Below %editw param is in the format '0XXXXX'                            
0019.00 C                   Eval      Output1    = %editw(Input1:'0     ')         
0020.00 C*                                                                         
0021.00 C* Below %editw param is in the format 'XX0XXX'                            
0022.00 C                   Eval      Output2    = %editw(Input2:'  0   ')         
0023.00 C*                                                                         
0024.00 C* Below %editw param is in the format '0XX/XX/XXXX'                       
0025.00 C                   Eval      Output3    = %editw(Input3:'0  /  /    ')    
0026.00 C*                                                                         
0027.00 C* Below %editw param is in the format 'XXX.XX000'                         
0028.00 C                   Eval      Output4    = %editw(Input4:'   .  000')      
0029.00 C*                                                                         
0030.00 C* Below %editw param is in the format '0XXX.XX000'                        
0031.00 C                   Eval      Output5    = %editw(Input5:'0   .  000')     
0032.00 C*                                                                         
0033.00 C* Below %editw param is in the format '0XXX.XX$'                          
0034.00 C                   Eval      Output6    = %editw(Input6:'0   .  $')       
0035.00 C*                                                                         
0036.00 C* Below %editw param is in the format 'XX0.XX000'                         
0037.00 C                   Eval      Output7    = %editw(Input7:'  0.  000')      
0038.00 C                                                                          
0039.00 C     Output1       DSPLY                                                  
0040.00 C     Output2       DSPLY                                                  
0041.00 C     Output3       DSPLY                                                  
0042.00 C     Output4       DSPLY                                                  
0043.00 C     Output5       DSPLY                                                  
0044.00 C     Output6       DSPLY                                                  
0045.00 C     Output7       DSPLY                                                  
0046.00 C                                                                          
0047.00 C                   Seton                                        LR        
        ****************** End of data ********************************************


Output

DSPLY   00012      
DSPLY     012      
DSPLY   05/05/2017 
DSPLY    1.23400   
DSPLY   012.34000  
DSPLY   012.34$    
DSPLY   12.34000   


Example-4: Use %EDITW to fill suppressed zeros with Asterisk(*)


The Asterisk(*) acts similar to the first zero. i.e. It's position in the format becomes the position where the suppression ends (similar to the first zero). The difference is that all suppressed zeros si replaced with becomes Asterisk(*).




 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00 D Input1          S              5P 0 Inz(00012)                           
0002.00 D Input2          S              5P 0 Inz(00012)                           
0003.00 D Input3          S              9P 2 Inz(0001234.56)                      
0004.00                                                                            
0005.00 D Output1         S             50A                                        
0006.00 D Output2         S             50A                                        
0007.00 D Output3         S             50A                                        
0008.00                                                                            
0009.00 C*                                                                         
0010.00 C* Below %editw param is in the format '*XXXXX'                            
0011.00 C                   Eval      Output1    = %editw(Input1:'*     ')         
0012.00 C*                                                                         
0013.00 C* Below %editw param is in the format 'XX*XXX'                            
0014.00 C                   Eval      Output2    = %editw(Input2:'  *   ')         
0015.00 C*                                                                         
0016.00 C* Below %editw param is in the format 'XXX*XXXX.XX'                       
0017.00 C                   Eval      Output3    = %editw(Input3:'   *    .  ')    
0018.00                                                                            
0019.00 C     Output1       DSPLY                                                  
0020.00 C     Output2       DSPLY                                                  
0021.00 C     Output3       DSPLY                                                  
0022.00 C                                                                          
0023.00 C                   Seton                                        LR
        ****************** End of data ********************************************


Output

DSPLY  *00012       
DSPLY  ***012       
DSPLY  ****1234.56  


Example-5: Use %EDITW with ampersand character


The ampersand character will be replaced with blanks. e.g. "&AM" will become " AM" in output.




 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00 D Input1          S              4P 0 Inz(1105)                            
0002.00 D Input2          S              5P 0 Inz(12345)                           
0003.00 D                                                                          
0004.00 D Output1         S             50A                                        
0005.00 D Output2         S             50A                                        
0006.00                                                                            
0007.00 C                                                                          
0008.00 C* Below %editw param is in the format 'XX.XXX&AM'                         
0009.00 C                   Eval      Output1    = %editw(Input1:'  .   &AM')      
0010.00 C*                                                                         
0011.00 C* Below %editw param is in the format 'XXX.XX&$'                          
0012.00 C                   Eval      Output2   = %editw(Input2:'   .  &$')        
0013.00                                                                            
0014.00 C     Output1       DSPLY                                                  
0015.00 C     Output2       DSPLY                                                  
0016.00 C                                                                          
0017.00 C                   Seton                                        LR
        ****************** End of data ********************************************


Output

DSPLY   1.105 AM  
DSPLY  123.45 $   










User Comments:



Subscribe

  Email:



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