ABAP trick for converting a floating point number to a packed field

Using ABAP, is there a simple way to convert a floating point number to a packed field?

    Requires Free Membership to View

You just assign the type f field to a type p field. You must specify the number of decimal places and the size of the packed field, and you should cater to overflows. Take a look at this example:

DATA: p TYPE p(12) DECIMALS 4,
      f TYPE f.

...

TRY.
    p = f.
  CATCH cx_sy_conversion_overflow.
    WRITE:/ 'Overflow'.
ENDTRY.

WRITE: f,p.

Note that calculations involving type p fields are slower than those using type f and type i, so take care when working on these type of fields.

This was first published in January 2006

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.