Friday, September 4, 2009

Convert Float To Packed Number


 We can use the round function to convert any FLTP value to packed number. Technically it is a rounding operation also. After having the rounded value in packed format , you can easily arrange your display format etc.



DATA : fl TYPE float.

DATA : pc TYPE p LENGTH 16 DECIMALS 2.





 
*** Just to try
fl = '-199.22' .



CALL FUNCTION 'ROUND'
  EXPORTING
    decimals      = 2
    input         = fl
    sign          = 'x'
  IMPORTING
    output        = pc
  EXCEPTIONS
    input_invalid = 1
    overflow      = 2
    type_invalid  = 3
    OTHERS        = 4.


IF sy-subrc > 0.
*** Sth Wrong

ELSE.
*** Now you’ve got your rounded value ”pc”

ENDIF.

No comments:

Post a Comment