cancel
Showing results for 
Search instead for 
Did you mean: 

Decimal Variable

Former Member
0 Kudos

How Do Everyone!

Please don't laugh at the following question but I can't

figure out what is happening in my code.

I have declared a variable:

wa_temp_amt type p decimals 2

I then move a value from an infotype to it say '2.00'.

So now wa_temp_amt contains 2.00. I then have the code

MULTIPLY wa_temp_amt BY '8.67', which wa_temp_amt should

then contain '17.34' but it displays '1734.00'

Any ideas?????

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Andy,

Please make sure "fixed point arithmetic" is checked in the attributes. That might solve the issue.

regards,

Ravi

Note : Please mark the helpful answers

Former Member
0 Kudos

Cheers guys for all your comments.

Adding the 'fixed point arithmetic' in the attributes

solved the problem.

Cheers Ravi

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Andy,

I suppose your multiplication statement is like this:

MULTiPLY a by '8.67' .

If this is the case, then there should not be any case of an error coming. I got the correct answer.

Regards,

SP.

Former Member
0 Kudos

wa_temp_amt type p decimals 2

I then move a value from an infotype to it say '2.00'.

wa_temp_amt = '2.00'.

after multiply store the value to another variable

like

data : wa_temp_amt type p decimals 2 value '2.00'.

data : wa_multi_by type p decimals 2 value '8.67'.

data : wa_multi_val type p decimals 2 .

wa_multi_val = wa_temp_amt.

wa_multi_val = wa_multi_val * wa_multi_by.

write 😕 wa_multi_val.

Thanks & regards

Sreenivasulu P

Former Member
0 Kudos

data:wa_temp_amt type p decimals 2.

wa_temp_amt = '2.00'.

wa_temp_amt = wa_temp_amt * '8.67'.

write:/ wa_temp_amt .

output-- 17.34.

vinod_gunaware2
Active Contributor
0 Kudos

U have to use <b>F</b> intead of packed.

Integer (I),Floating-point number (F) and Packed number (P).

<b>integers - type I</b>

The value range of type I numbers is -2*31 to 2*31-1 and includes only whole numbers. Non-integer results of arithmetic operations (e.g. fractions) are rounded, not truncated.

You can use type I data for counters, numbers of items, indexes, time periods, and so on.

<b>

Packed numbers - type P</b>

Type P data allows digits after the decimal point. The number of decimal places is generic, and is determined in the program. The value range of type P data depends on its size and the number of digits after the decimal point. The valid size can be any value from 1 to 16 bytes. Two decimal digits are packed into one byte, while the last byte contains one digit and the sign. Up to 14 digits are allowed after the decimal point. The initial value is zero. When working with type P data, it is a good idea to set the program attribute Fixed point arithmetic.Otherwise, type P numbers are treated as integers.

You can use type P data for such values as distances, weights, amounts of money, and so on.

<b>Floating point numbers - type F</b>

The value range of type F numbers is 1x10*-307 to 1x10*308 for positive and negative numbers, including 0 (zero). The accuracy range is approximately 15 decimals, depending on the floating point arithmetic of the hardware platform. 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.

Using I and F fields for calculations is quicker than using P fields. Arithmetic operations using I and F fields are very similar to the actual machine code operations, while P fields require more support from the software. Nevertheless, you have to use type P data to meet accuracy or value range requirements.

regards

vinod

Former Member
0 Kudos

Did u try wa_temp_amt = wa_temp_amt * '8.67'.