RETURN THE FRACTION / WHOLE VALUE OF A DECIMAL NUMBER

Return the fraction / whole value of a decimal number using MOD, DIV, FRAC or SHIFT :


The following ABAP code gives the fraction values of 1.3456.

PROGRAM:

*&---------------------------------------------------------------------*
*& Report  Z_VALUES_OF_FRACTION
*&
*&---------------------------------------------------------------------*
REPORT Z_VALUES_OF_FRACTION.
DATA: ld_decimal TYPE P DECIMALS 4 VALUE '1.3456',
        ld_fraction 
TYPE P DECIMALS 4,
        ld_fracstr 
TYPE string,
        ld_whole    
type i.

* Display full number with fraction
  
WRITE:/ 'Full number =', ld_decimal.

* Get the whole number
  ld_whole 
= ld_decimal DIV 1.
  
WRITE:/ 'Whole section =', ld_whole.

* Get the fraction value of number using MOD
  ld_fraction 
= ld_decimal MOD 1.
  
WRITE:/ 'Fraction =', ld_fraction.

* Get the fraction value of number using FRAC
  ld_fraction 
= FRAC( ld_decimal ).
  
write:/ 'Fraction =', ld_fraction .

* Get the fraction value of a decimal number using string manipulation
  ld_fracstr 
= ld_decimal.
  
shift ld_fracstr LEFT up to '.'.
  
shift ld_fracstr LEFT by 1 places.
  
write:/ 'Fraction =', ld_fracstr .



OUTPUT: