%ABS Built-In Functions in rpgle

%ABS function is used to get the Absolute value(Positive value) of a numeric expression.

It is used in the format %ABS(numeric expression).

We can use %ABS() function, when we want the expression result to be positive.

In example below, we are calculating Loss incurred in the sale of a book. But for reporting purpose, we need the result as positive value instead of negative value.

 

Example –%abs built-in function in rpgle

 




 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                    TESTRPG1
 FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
        *************** Beginning of data *****************************************
0001.00 D Sellprice       s              5p 0                                      
0002.00 D BuyPrice        s              5p 0                                      
0003.00 D Profit          s              5p 0                                      
0004.00 D Loss            s              5p 0                                      
0005.00 C                                                                          
0006.00 C                   Eval      Buyprice = 130                               
0007.00 C                   Eval      Sellprice = 120                              
0008.00 C                                                                          
0009.00 C                   If        Sellprice > Buyprice                         
0010.00 C                   Eval      Profit = Sellprice - Buyprice                
0011.00 C                   Else                                                   
0012.00 C                   Eval      Loss = %abs(Sellprice - Buyprice)            
0013.00 C                   Endif                                                  
0014.00 C                                                                          
0015.00 C     Profit        DSPLY                                                  
0016.00 C     Loss          DSPLY                                                  
0017.00 C                   Seton                                        LR        
        ****************** End of data ********************************************


Output

DSPLY      0
DSPLY     10 










User Comments:



Subscribe

  Email:



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