vicodin
How the new ABAP Data Type DECFLOAT helps computing complex calculation?

How the new ABAP Data Type DECFLOAT helps computing complex calculation?

It’s very rare for a programming language, when it gets enhanced with a new basic Data Type.

From SAP NetWeaver 7.10  ABAP has introduced a new built-in numeric type called DECFLOAT.

Find out what made SAP to come up with the new enhancement and what does it offer for performing complex calculations with more accuracy.

Author : Ajay

Author's Website | Articles from Ajay

Ajay is a Functional Consultant in Supply Chain Management. He is a SAP Certified SCM APO consultant and ABAP Developer. He is also involved in SAP implementations, Migration and Support activities as a Consultant. Follow me on Facebook

It’s very rare for a programming language, when it gets enhanced with a new basic Data Type.

From SAP NetWeaver 7.10  ABAP has introduced a new built-in numeric type called DECFLOAT.

Let’s welcome brand new member in the family, I mean DECFLOAT.

WHAT WAS THE NEED FOR THIS NEW ABAP DATA TYPE ?

The following picture gives us an idea about the numeric types which are available in ABAP until now.

ABAP_native_data_type

  • Integers are used for simple calculation
  • Floating points are variables are always approximate. Usually used for calculation of large values with decimal precision up to 15 places (Hardware dependent ).
  • So far Decimal Fixed point Type P (Based on BCD Encoding) were the only option which enable financial applications that require a high degree of accuracy

This type also has its own disadvantages.

1.Maximum length of a packed decimal is 16.

Which means the range of possible values is limited from -10³¹-1 to +10³¹-1 . How?

Lets review our basics!! A decimal variable can store (L*2-1) digits, where L is the length of variable in bytes.

So for packed decimal with length 16 we can store 16*2-1 = 31 digits. Each digit can have 10 possible values which gives us a possible range from -10^31-1 to +10^31-1.

This range poses a significant problem when calculating with very large values. Application developers are forced to implement complicated and error-prone work-arounds to handle the large numbers.

2. The number of decimal places is fixed.

Following the trend toward generic programming and re-use libraries, developers don’t always know how many decimal places are required when they write their code. Some industries or countries might require more or fewer decimal places than others.

3. Performance :

calculations using data type P are done completely in software and suffer
from the slowdowns software implementations inherently have

Calculations using data type P are done completely in software and suffer from the slowdowns software implementations inherently have.

So now these disadvantages of binary floating point numbers are addressed by introducing decimal floating point number.

New Decimal Floating-point Types in ABAP (IEEE754r)

DECFLOAT

Apart from the above two we have the generic type, DECFLOAT, which can represent either a DECFLOAT16 or a DECFLOAT34, makes it easy for developers to implement generic applications.

Lets have a look on some examples

Example:

1. DATA df34 TYPE decfloat34.

df34 = ‘123456.15′ –’123456′.

Result : 0.15

2.  df34 = round( val = ‘1234.56789′ dec = 3 ).

Result : 1234.568

3.  df34 = round( val = ‘1234.56789′ dec = 3

mode = cl_abap_math=>round_floor ).

Result : 1234.567


4. df34 = rescale( val = ‘2.0′ prec = 4 ).

Result : 2

Picture : Numeric types which are available in ABAP from Netweaver 7.01

Numeric-types

There are many new features in ABAP in Netweaver 7.01 which I am waiting to explore.

One Finishing Note : I never knew that not following up IEEE standards can even end up into disasters. In 1996 Ariane 5, a satellite lifting rocked exploded just because the software didn’t handle the exception caused by calculation overflow. (IEEE 754)

Thank God.. SAP is does not provide any product for launching rockets. :)



Like this post? Share it!

  • Tweet
  • Facebook
  • Diggit
  • Delicious
  • Diggit
  • Diggit
  • Diggit
  • Diggit
  • Diggit

ADVERTISE HERE


User Comments


  1. Tejas
    April 5, 2011

    Super…..

    Reply


    • Hoffman
      May 30, 2012

      Great video. My SAP NetWeaver install is a bit dienfreft but what a good guide. I was able to get this working with your video’s help (2+ days). Thank you! Any recommendations for a good site to go to get read BASIS notes/questions?Again thank you well done!

      Reply

Leave a Reply

:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!:
  Twitter Followers Email Updates