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: 

calculating a decimal

Former Member
0 Kudos

hello,

I am trying to calculate a field and the result is a decimal. the field is not showing the decimal amount. ep-hwsteaa has the amount of 80.00. ep-hwste has the amount of 200.00. w-dec should be 0.4. when I run in debug mode, w_dec is 0.000.

I am not sure if I have this coded right or not.

If someonw could please take a look at this and let me know what I am doing wrong, that would be very helpful

thanks in advance for the help

DATA: w_dec type P DECIMALS 3,

w_hwsteaa type p DECIMALS 2,

w_hwste type p DECIMALS 2.

  • l_steuer_ep-hwbas = ( ep-hwsteaa / ep-hwste ) * ep-hwbas.

w_hwsteaa = ep-hwsteaa.

w_hwste = ep-hwste.

w_dec = ( w_hwsteaa / w_hwste ).

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Go to the program attributes and make sure that "Fixed point arithmetic" is checked.

Rob

23 REPLIES 23

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please check the values of EP-HWSTEAA and EP-HWSTE.

It is fine in my system, please try this.


DATA: W_DEC TYPE P DECIMALS 3,
W_HWSTEAA TYPE P DECIMALS 2,
W_HWSTE TYPE P DECIMALS 2.
                                                                        
W_HWSTEAA = '80'.
W_HWSTE = '200'.
W_DEC = ( W_HWSTEAA / W_HWSTE ).

WRITE: /W_DEC.

Regards,

Ferry Lianto

Former Member
0 Kudos

Go to the program attributes and make sure that "Fixed point arithmetic" is checked.

Rob

Former Member
0 Kudos

Rob,

I check the attributes and the "Fixed point arithmetic" was not checked. I checked it

Ferry,

I tried your suggestion (after setting the fixed point arithmetic switch) and the result is still the same. w_dec still contains 0.000.

0 Kudos

I got 0.4 when I tested it with fixed point checked.

Did you save and activate?

Is this an include?

Rob

Message was edited by:

Rob Burbank

ferry_lianto
Active Contributor
0 Kudos

Hi,

As Rob suggested, please ensure the "Fixed point arithmetic" option is checked.

And try to regenerate the program again after the above option changed.

Regards,

Ferry Lianto

Former Member
0 Kudos

this is an include.

I am working with a Z copy of RFUMSV00. the include that I am trying to code the logic is zfi_rfums_selection_forms.

Former Member
0 Kudos

I tried this morning and the calculations are working correctly. is there something special with an include? whay would it not work yesterday wghen I made the change anf now this morning it is working.

0 Kudos

I believe the include program inherits the attributes from the main program.

Did you reset the attributes of the main program?

Rob

Former Member
0 Kudos

Rob,

I don't understand what you mean be reset the attributes. I changed the main program to check the box for the "fixed point arithmetic" and activated the program

0 Kudos

When did you activate the main program?

If you are modifying a copy of a standard SAP program, changing the attributesmay have unintended consequences. Does the unmodified version handle decimals correctly?

Rob

0 Kudos

Rob

I am assuming that it handles the decimals. I ran my copy of the report and looks excatly like the unmiodified production program except for the code changes that I have made for the new columns. I am not usre if within the program, or includes, or BADI's if they are doing decimal calculations.

0 Kudos

rob,

if this would be a problem and I would have to un-mark the attribute, how do you get around this. do you do the calculation and multiply the result by 100 to get a whole number. and then after you use this number do you divide the result by 100 to get the actual number?

0 Kudos

Hi,

Try this way


report  zars no standard page heading
        line-size 170
        line-count 65(4).
data: w_dec type p decimals 3,
w_hwsteaa type p decimals 2,
w_hwste type p decimals 2.

data : v_dec type p decimals 2.

w_hwsteaa = '80'.
w_hwste = '200'.
w_dec = ( w_hwsteaa / w_hwste ).

write: w_dec decimals 2.

move w_dec to v_dec.

write : / v_dec.

Former Member
0 Kudos

I have tried to run the program with the fixed point arithmetic attribute turned on. I am getting another dump at a different place. since the original program did not have this attribute turned, I am a liile heistant to turn it on. that being said, is there a way for me to get my calculation with having to turn on this attribute. I have tried all of the code examples in this thread but none of them work. I found something where you can enable and display this fixed point attribute bbut I am not sure how to use this

INSERT REPORT prog FROM itab

                             {

                             | {

                                

                                 }

                             | }

                             .

0 Kudos

Hi,

Check this link from SAP docu

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb2d0c358411d1829f0000e829fbfe/content.htm

+

If the attribute Fixed point arithmetic is set for a program, the system rounds type P fields according to the number of decimal places or pads them with zeros. The decimal sign in this case is always the period (.), regardless of the user’s personal settings. We recommend that you always set the fixed point arithmetic attribute.

+

0 Kudos

Have you tried A@RS first suggestion?

Rob

0 Kudos

I copied this program from a SAP standard program. the standard program does not have this coded. I have changed the attribute in my program and made the corrections to correct the dump ( dumping on the statement hlp_hwnet = 1000000000000.). I am running the standard program and my program with the same parameters and the numbers look like they are matching

0 Kudos

yes I did and I did not get any result for w_dec. all I got was zeros

0 Kudos

I took the code and created a test program with the fixed point arithmetic attribute not checked. I did not check any values, only zeros

0 Kudos

Hi,

The following is the documentation i have a got , when i press F1 on Fixed Point Arthemetic

+

If you do not, packed numbers (ABAP/4 type P, Dictionary types CURR, DEC or QUAN) will be treated as integers when they are used in assignments, comparisons and calculations, irrespective of the number of decimal places defined. Intermediate results in arithmetic calculations will also be rounded to the next whole number. The number of decimal places defined is only taken into account when you output the answer using the WRITE statement.

+

0 Kudos

does,

I have checked the attribute and the calculation worked. I ran the standard program which did not have the attribute set and my program which does have the attribute set and the reports were identical in the amounts. what I didn't know is that I had bad test data. all of the test data were whole numbers (numbers that had no cents). when the user ran this against real data, the report did not show the cents amount. so now I have to uncheck this attribute and I am back to square one. I have to find a way to do my calculations without having this attribute checked. If anyone has any ideas on how to do this, it would be a big help. I have tried all of the examples that were sent to me in this post and I still get zero amounts when I run them

thanks in advance for any help

0 Kudos

hello,

I found in another post where the person got around this issue by creating a function module in a function group that had the fixed point arithmetic attribute checked. is this the only way that I can get my calculations to worked?

thanks...

Former Member
0 Kudos

corrected on my own. I had to create new Z tables to include decimals