Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

parameters declaration

Former Member
0 Kudos

Hello ,

Why can't we declare parameters of type float .

example :

parameters flt type f.

is not allowed in abap ..Why?

Moderator message: please search for available information/documentation.

Edited by: Thomas Zloch on Feb 23, 2011 11:58 AM

5 REPLIES 5

Former Member
0 Kudos

Hi,

Float Data Type cannot be declared in Parameters.

If we want to use float values in our input, use packed no's or char as datatype.

Try the following code snippets, You 'll get an idea.

Code Snippets:

1. PARAMETERS : A(4) TYPE P DECIMALS 2,

B(4) TYPE P DECIMALS 2.

DATA : C(4) TYPE P DECIMALS 2.

C = A + B.

WRITE : / u2018THE SUM ISu2019 , C.

Ouput is : THE SUM IS 4,20 (Input A: 1,6, B= 2,6)

2. PARAMETERS : A(8) TYPE c,

B(8) TYPE C.

DATA : C(10) TYPE C

C = A + B.

WRITE : 'THE SUM IS' , C.

output: THE SUM IS 4.2 (Input A: 1.6, B= 2.6).

<removed by moderator>

Moderator message: do not beg for points, points removed.

Edited by: Thomas Zloch on Feb 23, 2011 11:57 AM

Former Member
0 Kudos

Hello Arun Prasath Kumar ,

The point which i want to know is : why we are coding in this manner ? why can't we declare it as of float type ..?

0 Kudos

Hi Manish,

Floating point is internally converted to a binary system, hence rounding error will occur.

we wont get the accurate value. So we'll use Packed no's instead of F for accuracy.

In parameters, Floating point variable is not allowed. If you want the reason why it is not allowed, Contact SAP and post the reasons in Forum, which will be useful for us.

Have u tried using Floating type for the data C in the code snippet I'd given in the previous post, If u tried to simulate, U wouldnt probably get this question.

Regards,

Arun Prasath Kumar.

0 Kudos

hello ,

Thanks , I got it .

Edited by: Manish Gupta on Feb 23, 2011 9:15 AM

Former Member
0 Kudos

Hi manish,

Since type F data is internally converted to a binary system, rounding errors can

occur. Although the ABAP processor tries to minimize these effects, you

should not use type F data if high accuracy is required. Instead, use type P

data.

You use type F fields when you need to cope with very large value ranges and

rounding errors are not critical.

Regards

Seema Sharma.

Moderator message: copy/pasted, points removed, do not repeat!

Edited by: Thomas Zloch on Feb 23, 2011 11:56 AM