Q

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

Learn a trick for converting a floating point number to a packed field in this expert Q and A with development guru Matt Billingham.

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

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 last published in January 2006

Dig Deeper on SAP ABAP

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

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

Please create a username to comment.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close