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

multiplication problem

former_member841898
Participant
0 Likes
2,111

hello all,

in a customize abap program i am multiplying two fields and storing them in another variable

those two fields are vbrk-netwr(data type - curr , length 15 decimals 2) and

vbrk-kurrf (data type- dec , length 9 decimals 5).

i have declared my variables in following way:

tables: vbrk.

data: begin of itab occurs 0,

vbeln TYPE vbrk-vbeln,

kurrf like vbrk-kurrf,

netwr like vbrk-netwr,

x like vbrk-netwr,

end of itab.

start-of-selection.

SELECT vbeln kurrf netwr

FROM vbrk

INTO TABLE itab.

loop at itab.

itab-x = itab-netwr * itab-kurrf.

MODIFY itab.

ENDLOOP.

end-of-selection.

loop at itab.

write:/ itab-vbeln,

itab-netwr ,

itab-kurrf,

itab-x,

endloop.

all the values are coming ok except itab-x. for eg.

90006752 vbeln

340,000.00 netwr

1.00000 kurrf

34,000,000,000.00 x (wrong should be 340,000.00)

90005531 vbeln

1 00,000.00 netwr

62.15000 kurrf

621,500,000,000.00 x (wrong shoul be 6215000.00)

regards

pankaj

14 REPLIES 14
Read only

Former Member
0 Likes
1,644

Hi Pankaj,

ITAB-X is a type of VBRK-NETWR,,,

it dosent stiore more than 2 decimal points...

please change that one to itab-x type p decimals 5.

thats it .. if still problem exits change ITAB-X to char..

Thanks & regards,

Dileep .C

Read only

Former Member
0 Likes
1,644

Pankaj,

As far as I know, the problem is with the decimal point multiplication. As you are multiplication the variables having different decimal notation, this could be the problem.

Try to type cast it in to a temporary variable of same type before multipling it and check the result.

I am not sure whether that would work. But, thot of giving a pointer.

Thanks,

Babu Kilari

Read only

Former Member
0 Likes
1,644

Hi,

Use all the variables having same type, then you will get the result what u want

Read only

former_member841898
Participant
0 Likes
1,644

hi all,

not solved

regards

pankaj

Read only

0 Likes
1,644

hi,

try the below code which might help u :-



report ZNEW32."  NO STANDARD PAGE HEADING
                " LINE-SIZE  80
                " LINE-COUNT 65.

tables: vbrk.

data: begin of itab occurs 0,
vbeln TYPE vbrk-vbeln,
kurrf like vbrk-kurrf,
netwr like vbrk-netwr,
x like vbrk-netwr,
y(16) TYPE p DECIMALS 2,
end of itab.

start-of-selection.
SELECT vbeln kurrf netwr
FROM vbrk UP TO 10 ROWS
INTO TABLE itab.

loop at itab.
itab-x = itab-netwr * itab-kurrf.
itab-y = itab-x.
MODIFY itab.
ENDLOOP.

end-of-selection.

loop at itab.
write:/ itab-vbeln,
itab-netwr ,
itab-kurrf,
itab-x,
itab-y.
endloop.


OUTPUT:-

400000                21,195.05   1.00000                21,195.05                         21,195.05
400001                37,395.09   1.00000                37,395.09                         37,395.09
400002                21,195.05   1.00000                21,195.05                         21,195.05
400003                37,395.09   1.00000                37,395.09                         37,395.09
400004                76,477.68   1.00000                76,477.68                         76,477.68
400005                91,158.12   1.00000                91,158.12                         91,158.12
400006               101,894.37   1.00000               101,894.37                        101,894.37
400007                45,022.60   1.00000                45,022.60                         45,022.60
400008                68,418.60   1.00000                68,418.60                         68,418.60
400009                58,749.31   1.00000                58,749.31                         58,749.31

revert back if it useful for u or not.

Edited by: ricx .s on May 4, 2009 10:51 AM

Edited by: ricx .s on May 4, 2009 10:59 AM

Read only

0 Likes
1,644

hi ricx ,

when i m executing ur code see thae value of itab-x and itab-y.

multiplication problem still exists.

53000001               1,500.00   39.40000        5,910,000,000.00                  5,910,000,000.00
53000002                 483.00   33.35000        1,610,805,000.00                  1,610,805,000.00
53000003              22,320.00   1.00000         2,232,000,000.00                  2,232,000,000.00
53000004              52,098.00   1.00000         5,209,800,000.00                  5,209,800,000.00
53000005             207,142.50   1.00000        20,714,250,000.00                 20,714,250,000.00
53000006               7,000.00   1.00000           700,000,000.00                    700,000,000.00
53000007             224,850.00   1.00000        22,485,000,000.00                 22,485,000,000.00
53000008              11,635.34   1.00000         1,163,534,000.00                  1,163,534,000.00
53000009                 510.00   1.00000            51,000,000.00                     51,000,000.00
53000010              17,680.00   1.00000         1,768,000,000.00                  1,768,000,000.00

Read only

0 Likes
1,644

Hi Pankaj,

I have a good news for you,

None of the above code will work,,,!

Since your original code is perfect. I just now copied & executed your code,

its working fine for me. I am using 4.7 EE

just check with your settings once again,,,

Thanks & regards,

Dileep .C

Read only

0 Likes
1,644

hi dileep,

i m using ecc6.0 version ,

from where i will check the setting

regards

pankaj

Read only

0 Likes
1,644

Hi Pankaj,

I am not sure but.

Please check Decimal notation in defaults in SU01 Tcode.

Also do some other calculations.. apart from your requirement.. and do ask you friends in office to run your code,, is their settings are correct.

Thanks & regards,

Dileep .C

Read only

Former Member
0 Likes
1,644

Use x field as character field shown below..

data: begin of itab occurs 0,

vbeln TYPE vbrk-vbeln,

kurrf like vbrk-kurrf,

netwr like vbrk-netwr,

x(15) TYPE c,

end of itab.

Hope it will solve ur problem...i tried, it working...

Read only

0 Likes
1,644

hi mujib,

my data is not coming correct.

90006752 vbeln

340,000.00 netwr

1.00000 kurrf

34,000,000,000.00 it is wrong

right value should be 340,000.00

regards

pankaj

Read only

Former Member
0 Likes
1,644

hi pankaj,

I tried it at my end using ur 'X' field as character type. it works...

for eg-

93098129 497,303.64 1.00000 497303.64

93098130 506,437.80 1.00000 506437.8

93098131 425,245.36 1.00000 425245.36

93098132 497,811.10 1.00000 497811.1

93098133 465,841.58 1.00000 465841.58

90238836 2,210.00 1.00000 2210

94814635 3.00 39.85000 119.55

90238837 686.52 1.00000 686.52

90238838 2,553,854.40 1.00000 2553854.4

90238839 2,343,321.60 1.00000 2343321.6

90238840 2,305,563.00 1.00000 2305563

90238841 2,156,817.00 1.00000 2156817

90238842 114,420.00 1.00000 114420

90238843 194,514.00 1.00000 194514

90238844 114,420.00 1.00000 114420

90238845 57,210.00 1.00000 57210

90238846 252,575.00 1.00000 252575

Read only

Former Member
0 Likes
1,644

Yaar I get the same problems when i use NETWR, i don't know why. So another way i fixed this problem is devide the result by 10000 I know it's not a perfect solution but still.

loop at itab.

itab-x = itab-netwr * itab-kurrf / 10000.

MODIFY itab.

ENDLOOP.

Hey i copied and ran ur program and its running perfect, no need to change anything. i don't know why ur system is behaving that way.

Result:

test

90000000 404,916.62 1.00000 404,916.62

90000001 10,243.96 1.00000 10,243.96

90000002 309,922.54 1.00000 309,922.54

90000003 259,529.70 1.00000 259,529.70

90000004 10,243.96 1.00000 10,243.96

90000005 20,487.92 1.00000 20,487.92

90000006 10,243.96 1.00000 10,243.96

90000007 7,202.96 1.00000 7,202.96

90000008 5,503.89 1.00000 5,503.89

90000009 601,100.20 1.00000 601,100.20

Edited by: Tripat Pal Singh on May 5, 2009 9:48 AM

Edited by: Tripat Pal Singh on May 5, 2009 9:49 AM

Read only

0 Likes
1,644

hi all

thanks all of u for your useful contributions:

the problem has been resolved.

by checking the fixed-point arithmetic checkbox in attribute section of se38.

regards

pankaj