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

type casting with decimals

Former Member
0 Likes
2,296

I have three data objects

mglme length 13, decimal 3 type quan

kbetr length 11, decimal 2 type curr

netwr length 15, decimal 2 type curr

I need to do kbetr = netwr / mglme

But I never get the right value because of the difference in data lengths

for e.g. netwr = 150.00 and mglme = 10.000 returns kbetr = .015

Any help on how to solve this. Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,604

I have three data objects

mglme length 13, decimal 3 type quan

kbetr length 11, decimal 2 type curr

netwr length 15, decimal 2 type curr

declare three variables temporary.

data : lv_kbetr like vbak-netwr.

data : lv_mglme like vbak-netwr.

data : lv_netwr like vbak-netwr.

clear : lv_kbetr,

lv_mglme,

lv_netwr.

move : kbetr to lv_kbetr,

mglme to lv_mglme,

netwr to lv_netwr.

lv_kbetr = lv_netwr / lv_mglme.

move lv_kbetr to kbetr.

Now see the results.

4 REPLIES 4
Read only

Former Member
0 Likes
1,604

Hi Megan,

Round off the decimals of all the fields before you do the division.

Check this thread for round off of decimals.

Hope it solves your problem.

Thanks

Aneesh.

Read only

Former Member
0 Likes
1,605

I have three data objects

mglme length 13, decimal 3 type quan

kbetr length 11, decimal 2 type curr

netwr length 15, decimal 2 type curr

declare three variables temporary.

data : lv_kbetr like vbak-netwr.

data : lv_mglme like vbak-netwr.

data : lv_netwr like vbak-netwr.

clear : lv_kbetr,

lv_mglme,

lv_netwr.

move : kbetr to lv_kbetr,

mglme to lv_mglme,

netwr to lv_netwr.

lv_kbetr = lv_netwr / lv_mglme.

move lv_kbetr to kbetr.

Now see the results.

Read only

Former Member
0 Likes
1,604

data : var1 type p decimals 3,

var2 type p decimals 2.

curr and quan are database data type so you can not reffer them in your abap program the abap type is type p.

regards

shiba dutta

Read only

former_member186741
Active Contributor
0 Likes
1,604

I don't believe this is happening becasue of the differences in the data lengths. I think it is because you are dealing with currency fields without referencing the involved currency. Some currencies, eg japanese yen, don't have decimal places, for all I know some may have more than 2. SAP gets round this by defining the attributes of each currency. The currency related variables can only be adjusted to the appropriate number of decimal places when they refer to the currency involved. If no currency reference is provided how can SAP work out how many decimal places you want to work with?

FOR EXAMPLE, create this simple program and you'll see what I mean.

REPORT ZNRW_CURRENCY .

parameters: P_curr1 type t001-waers default 'JPY',

p_curr2 type t001-waers default 'USD'.

DATA W_VALUE TYPE marc-VKUMC VALUE 1.

WRITE:/ W_VALUE CURRENCY P_CURR1,P_CURR1.

WRITE:/ W_VALUE CURRENCY P_CURR2,P_CURR2.