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

Quantity converting incorrectly

Former Member
0 Likes
1,795

Hello,

I've got some code in a userexit (userexit_save_doc_prepare) that needs to convert a sales order's quantity (vbap-kwmeng) to an integer so that I can do further calculations with it. However, the automatic conversion routines seem to be misfiring, and they also seem to be dependent on user settings (comma decimals vs. period decimals). Here is a summary of the code and what it is doing:

DATA: temp_quantity_out TYPE I.

LOOP AT xvbap.

    temp_quantity_out = xvbap-kwmeng.

ENDLOOP.

When I go to this part of the code in debug mode after entering '2' in the quantity of the material, the value it shows for xvbap-kwmeng is '2.000'. However, after executing the conversion, the field temp_quantity_out has the value of '2000', instead of the '2' I was expecting. This is throwing future calculations off. How do I get a value of '2' from this field?

I've tried using a packed number. I've tried using 'write to'. I've tried using it to calculate without converting. None of these have worked. I even tried to find a conversion function, but didn't see anything. Can you help?

Thanks,

Nathan Beeler

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,220

Nathan, I believe that you are seeing this behavior due to an attribute of the program itself. In the MAIN program, SAPMV45A, click Go To->Attributes. In the dialog that appears, check to see if "Fix-Point Arithmatic" is checked. If it is not, then this is causing your problem. An easy fix is to check this on, but make sure that you test everything else thoroughly and make sure that every is ok. Otherwise, you will need to divide by 1000 when moving to your INT field.

It would be safer to divide by 1000, instead of marking as "Fix point arithmatic", SAP has left it off for a reason.

Regards,

Rich Heilman

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,221

Nathan, I believe that you are seeing this behavior due to an attribute of the program itself. In the MAIN program, SAPMV45A, click Go To->Attributes. In the dialog that appears, check to see if "Fix-Point Arithmatic" is checked. If it is not, then this is causing your problem. An easy fix is to check this on, but make sure that you test everything else thoroughly and make sure that every is ok. Otherwise, you will need to divide by 1000 when moving to your INT field.

It would be safer to divide by 1000, instead of marking as "Fix point arithmatic", SAP has left it off for a reason.

Regards,

Rich Heilman

Read only

0 Likes
1,220

Thank you, Rich, for the quick response. I would like to do the safer route and divide by 1000. However, before I do can you tell me if that will always give a correct result - even for my coworker who uses 0,000 decimal notation.

-Nathan

Read only

0 Likes
1,220

Nathan, the external formatting is user specific per their user settings, however, this is EXTERNAL format only. During the internal processing of the program, this field will always have a '.' as the decimal separator and it will not have any thousands separator. It will always look like 12345678.000 in debug mode. So for this field, since it has 3 decimal places, the dividing by 1000 will always work.

Regards,

Rich Heilman

Read only

0 Likes
1,220

Thanks Rich! Problem solved. Hopefully I will remember all this stuff when I run into it again in a few years (as I always seem to do).