Ask the Expert

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: