Application Development and Automation 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: 
Read only

multiply the packed values

Former Member
0 Likes
3,006

hi all,

please look at the below eg:

data : text1 type p decimals 2.

data : text2 type p decimals 2.

data : text3 type p decimals 2.

text1 = '328.70'.

text2 = '0.02'

text3 = text1 * text2.

after multiplication the value is 657.40. but the actual value should be 6.57 what the reason for this errored value 657.40 have is missed some thing over here??? please help

Regards,

Jayakumar.R

12 REPLIES 12
Read only

MarcinPciak
Active Contributor
1,997

Hi,

Ensure that in programs Atributes you have checked Fixed point arithmetic .

Regards

Marcin

Read only

Former Member
1,997

hi,

check program attributes:

<fixed point arithmetic> should be marked...

regards,darek

Read only

Former Member
0 Likes
1,997

Its correct, I just copied ur code and pasted as below:

data : text1 type p decimals 2.

data : text2 type p decimals 2.

data : text3 type p decimals 2.

text1 = '328.70'.

text2 = '0.02'.

text3 = text1 * text2.

write : text1,text2,text3.

Its giving me 328.70 0.02 6.57

Fixed point aithmetic should be selected in atribute.

Read only

Former Member
0 Likes
1,997

Hi Jay,

The problem is that your decimal point is being recognized as a thousand separator. Replace '.' with a comma ',', and your calculation should work fine.

Try this:

data : text1 type p decimals 2.

data : text2 type p decimals 2.

data : text3 type p decimals 2.

text1 = '328,70'.

text2 = '0,02'.

text3 = text1 * text2.

You should get it right now. If you want to change your settings, goto SAP Easy Access -> Settings -> Own Data

Hope this helps! Do let me know if you need anything else!!

Cheers,

Shailesh.

Always provide feedback for helpful answers!

Read only

sridhar_meesala
Active Contributor
0 Likes
1,997

Hi,

Try this.

data : text1 type p decimals 2 VALUE '328.70'.
data : text2 type p decimals 2 VALUE '0.02'.
data : text3 type p decimals 2.

text3 = text1 * text2.

WRITE text3.

Thanks,

Sri.

Read only

Former Member
0 Likes
1,997

jaya,

your code is correct and fetching correct value.

check if you have written some thing else in the code.

Read only

0 Likes
1,997

hi,

actually the value are picked from database field kwert,

for example i just entered the values in quotes.

regards,

R.Jayakumar

Read only

0 Likes
1,997

>

> hi,

>

> actually the value are picked from database field kwert,

> for example i just entered the values in quotes.

>

> regards,

> R.Jayakumar

This is not important as KWERT is of type DEC so the one which you used in your example.

Did you check the setting together with Darek we suggested you?

When it is set, SAP does calculation same way as you would do multiplication on sheet of paper, so decimal point is taken under considertation (4 places shifted to left after applied to result).

On the other hand, when you have that option off, it will leave that point at 2nd place shifted to left, hence you get 657.40 instead of 6.57.

Regards

Marcin

Read only

0 Likes
1,997

hi,

i have checked the same expression in report it works fine. But, in pricing routine it returns wrong value. plz help

Regards,

R.Jayakumar

Read only

0 Likes
1,997

hi

try to do your calculation in external program with fixed point arithemtic checked...

darek

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,997

Look at SAP documentation [Numeric Data Types |http://help.sap.com/abapdocu_70/en/ABENNUMBER_TYPES.htm]

If you are using packed numbers, you should always set the program attribute fixed point arithmetic as only this ensures that the decimal point is correctly calculated. Otherwise, all numbers are specified as integers and all intermediate results for the next integer are rounded. If fixed point arithmetic is not set, the decimal places defined for the number only appear in screen output or when formatting with WRITE [TO].

Regards,

Raymond

Read only

Former Member
0 Likes
1,997

Hi,

Please Check that in your programs atributes you have checked Fixed point arithmetic .

Thanks & Regards,

Shreemohan