cancel
Showing results for 
Search instead for 
Did you mean: 

Divide by zero error in DP Macro

Former Member
0 Kudos

Hi Experts,

I am creating a macro as whenever (KF1-KF2)/KF2 is greater than 0.2 the cell for KF1 should become red in color. While executing the macro, I am getting an ABAP dump for the error 'Divide by zero'. The following screenshots describe the situation.

In the step settings, I have made 'For missing values- No calculations', but still if KF 'Final Approved Forecast' is blank, system gives the ABAP dump for divide by zero.

working fine under this situation-

Throwing error under this situation-

How to avoid this error?

Regards

Manotosh

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

in the case that kf "Final approved fcst" is zero, you are actually dividing by zero, which is not permitted.

One way out is:

IF( b <> 0 )

      y = a / b

ELSE

     y = [special value]

ENDIF

You should decide what your "special value" should be for your business case: when there is no final approved fcst but there is an allocation... what is the value you want for your resulting variance?

regards,

J.

Former Member
0 Kudos

Hi James,

Thanks for your revert.

I understand the workaround. But the matter is, when I am setting the radio button as 'No calculations' in case of missing values, then why system still considers it as zero and tries to calculate? In such case, what is the use of setting this radio button.

Regards

Manotosh

Former Member
0 Kudos

Hi,

sorry, I did not read your full post.

I don´t usually use that particular option, but as I always understood it, it refers to working on columns outside your range (such as if you use offsets to get values from keyfigures). If you stay in the defined range, you need to protect the division operation regardless of your settings (to my knowledge).

You can easily give it a try, build a macro that does KF_B(t) =  KF_A(t-1) with KF_A(t)=1 for the whole horizon and check the effect of the setting in KF_A. As I said, I never tried. I always write the macro so I don't need this.

regards,

J.