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: 

XKOMV-KWERT isn't calculated while creating an order

florianbus
Contributor
0 Kudos

Hi,

I created the following calculation rule:

FORM FRM_KONDI_WERT_907.

XKOMV-KBETR = KOMP-KZWI2.

XKOMV-KBETR = XKOMV-KBETR * 1000 / KOMP-MGAME.

XKOMV-KWERT = XKOMV-KBETR / 1000 * KOMP-MGAME.

ENDFORM.

If I now create an order, XKOMV-KWERT isn't calculated, means value = 0,00. After changing eg. the price, it's correctly calculated. The same after saving the order, the XKOMV-KWERT is filled with the right value.

Please help me to get this working right.

Thank you and regards,

Florian

1 ACCEPTED SOLUTION

Former Member
0 Kudos

You may have to save the value in XKWERT instead of (or in addition to) XKOMV-KWERT.

This may be due to scoping issues.

One suggestion I would make is to put a breakpoint in your routine and look at the call stack when you create an order vs. when you change or save an order.

You may find that you have a different context in each situation (as I found with regard to XKOMV with some VOFM pricing requirements), so that you cannot rely on the integrity of XKOMV without some extra work, since the scoping might be different in each case.

If that is the case, we may have to go into further detail. There is a workaround for that.

But first try using XKWERT.

Basically, at the end of your routine:

XKWERT = XKOMV-KWERT.

(I still think you should simplify your other logic to eliminate the possibility of rounding errors.)

Good luck

Brian

Message was edited by:

Brian Sammond

5 REPLIES 5

Former Member
0 Kudos

> Hi,

>

> I created the following calculation rule:

> FORM FRM_KONDI_WERT_907.

> XKOMV-KBETR = KOMP-KZWI2.

> XKOMV-KBETR = XKOMV-KBETR * 1000 / KOMP-MGAME.

> XKOMV-KWERT = XKOMV-KBETR / 1000 * KOMP-MGAME.

> FORM.

>

> If I now create an order, XKOMV-KWERT isn't

> calculated, means value = 0,00. After changing eg.

> the price, it's correctly calculated. The same after

> saving the order, the XKOMV-KWERT is filled with the

> right value.

>

> Please help me to get this working right.

>

> Thank you and regards,

> Florian

Why not simplify?

You may be getting the result as 0 because of the way intermediate results are calculated.

I have found that if you do a division by a large number followed by a multiplication, significant digits can be lost if the intermediate result is rounded to a set number of decimal places.

This may be the case with your statement:

XKOMV-KWERT = XKOMV-KBETR / 1000 * KOMP-MGAME.

When you divide by 1000 you may lose significant digits, and possibly end up with a zero value. Multiplying my KOMP-MGAME makes no difference then.

For example KBETR only has 2 decimals.

If the value of KBETR is 1.00 and you divide by 1000, this would be .001, and this will be rounded to 0.00.

Where I have to do such calculations, I always do the multiplications first to reduce the possibility of such errors (this assumes that the operands are expected to be > 1. If the operands are expected to be <1 the opposite is true.).

In addition, you can simplify your code since the final statement is simply taking the calculated value of KBETR and reversing the effects of the prior calculation, which basically should return the value from KZWI2 into KWERT, so why go through these steps?

In such a case why not just save the original value, as I have done below.

FORM FRM_KONDI_WERT_907.
  XKOMV-KWERT = KOMP-KZWI2.
  XKOMV-KBETR = KOMP-KZWI2 * 1000 / KOMP-MGAME.
ENDFORM.

Also, verify if you original logic is correct.

If would appear that KWERT will end with the condition subtotal from KZWI2, and KBETR will have the subtotal multiplied by 1000 divided by the quantity.

Is this correct?

Good luck

Brian

0 Kudos

Hi Brian,

so far my rule calculates the values right but they just appear after saving the document or changing the storage location or doing a new calculation (but not with A) or changing the calculation value PR00 or changing the amount of VBAP-ZMENG. KOMV-KWERT isn't calculated after first entry of the item.

Any ideas?

Regards,

Florian

Former Member
0 Kudos

You may have to save the value in XKWERT instead of (or in addition to) XKOMV-KWERT.

This may be due to scoping issues.

One suggestion I would make is to put a breakpoint in your routine and look at the call stack when you create an order vs. when you change or save an order.

You may find that you have a different context in each situation (as I found with regard to XKOMV with some VOFM pricing requirements), so that you cannot rely on the integrity of XKOMV without some extra work, since the scoping might be different in each case.

If that is the case, we may have to go into further detail. There is a workaround for that.

But first try using XKWERT.

Basically, at the end of your routine:

XKWERT = XKOMV-KWERT.

(I still think you should simplify your other logic to eliminate the possibility of rounding errors.)

Good luck

Brian

Message was edited by:

Brian Sammond

Former Member
0 Kudos

hi gurus,

i'm not getting any calculated result its giving some unknown value, which is not matching.

the code is......

FORM FRM_KONDI_WERT_600.

XKWERT = komp-KZWI1 * 100 / ( 100 + komp-kzwi2 ) .

XKWERT = XKOMV-KWERT.

endform.

here i need to get the value of KZWI1 & kZWI2 IN THE CALCULATION FOR PRICING ROUTINE WHICH I'M DEVELOPING.

in debugging its showing the values being picked but not doing the correct calculation.

plzzzzz help me.......

Edited by: SAURAV MUKHERJEE on Mar 17, 2008 1:10 PM

0 Kudos

Hi Saurav,

I changed my calculation to this and it worked:

XKOMV-KBETR = KOMP-KZWI2.

XKOMV-KBETR = XKOMV-KBETR * 1000 / KOMP-MGAME.

XKWERT = ( XKOMV-KBETR * KOMP-MGAME / 1000 ) * KOMP-ANZ_MONATE.

As I see, you are overwriting XKWERT with the value of XKOMV-KWERT (XKWERT = XKOMV-KWERT.). So the before calculated value of XKWERT is gone.

Maybe this helps you.

Regards,

Florian