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: 

Runtime error :COMPUTE_BCD_OVERFLOW

Former Member
0 Kudos

Hi,

I am getting the run time error as "Overflow for arithmetical operation (type P) in program".

Here is the part of my code.

Types:  begin of ty_nriv,

         OBJECT    type NROBJ,

         SUBOBJECT type NRSOBJ,

         NRRANGENR   type NRNR,

         TOYEAR     type NRYEAR,

         minnumber   type NRFROM,

         maxnumber   type NRto,

         CurrentNumber type NRLEVEL,

         No_range type NRTO,

         useage   type P decimals 6, 

         M_dooms  type P decimals 4,

       end of ty_nriv.


data:g_object type nriv-object,
       tab_nriv type standard table of TY_nriv ,
       WA_NRIV TYPE TY_NRIV,
      GV_YEAR(4) TYPE N,.

*selection screen

select-options:  s_object for g_object .

*start-of-slection.

select  OBJECT

           SUBOBJECT

           NRRANGENR

           TOYEAR

           FROMNUMBER

           tonumber

           NRLEVEL

           from nriv

           into table tab_nriv

          where object in s_object

             and TOYEAR < GV_YEAR.
 

  loop at tab_nriv into wa_nriv.
 

    WA_NRIV-No_range = WA_NRIV-maxnumber - WA_NRIV-minnumber + 1 .
 

    wa_nriv-useage = ( ( wa_nriv-currentnumber - wa_nriv-minnumber + 1 ) / WA_NRIV-No_range ) * 100 .

 
    wa_nriv-M_dooms = 50 / ( ( ( wa_nriv-currentnumber - wa_nriv-minnumber + 1 ) / ( wa_nriv-No_range + 1 ) )

      / ( 1 - ( wa_nriv-currentnumber - WA_NRIV-minnumber + 1 ) / ( WA_NRIV-No_range + 1 ) ) ).

 
      modify tab_nriv from wa_nriv transporting  No_range useage M_dooms.

 
  endloop.

Please help me out in this issue.

Thanks,

*P.S- I have tried with increase the length of packed type of decimals 10 and with data element KTMNG.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Swetha,

I guess the following calculation causes division by zero ( which is infinity ) somewhere, so you are getting this dump


wa_nriv-M_dooms = 50 / ( ( ( wa_nriv-currentnumber - wa_nriv-minnumber + 1 ) / ( wa_nriv-No_range + 1 ) )
 
      / ( 1 - ( wa_nriv-currentnumber - WA_NRIV-minnumber + 1 ) / ( WA_NRIV-No_range + 1 ) ) ).

You can give that calculation inside try catch to avoid the dump and capture the error.. like


TRY.
wa_nriv-M_dooms = 50 / ( ( ( wa_nriv-currentnumber - wa_nriv-minnumber + 1 ) / ( wa_nriv-No_range + 1 ) )
 
      / ( 1 - ( wa_nriv-currentnumber - WA_NRIV-minnumber + 1 ) / ( WA_NRIV-No_range + 1 ) ) ).
CATCH CX_ROOT.
  Message 'Error'.
ENDTRY.

Cheers,

Kothand

4 REPLIES 4

Former Member
0 Kudos

Hi Swetha,

I guess the following calculation causes division by zero ( which is infinity ) somewhere, so you are getting this dump


wa_nriv-M_dooms = 50 / ( ( ( wa_nriv-currentnumber - wa_nriv-minnumber + 1 ) / ( wa_nriv-No_range + 1 ) )
 
      / ( 1 - ( wa_nriv-currentnumber - WA_NRIV-minnumber + 1 ) / ( WA_NRIV-No_range + 1 ) ) ).

You can give that calculation inside try catch to avoid the dump and capture the error.. like


TRY.
wa_nriv-M_dooms = 50 / ( ( ( wa_nriv-currentnumber - wa_nriv-minnumber + 1 ) / ( wa_nriv-No_range + 1 ) )
 
      / ( 1 - ( wa_nriv-currentnumber - WA_NRIV-minnumber + 1 ) / ( WA_NRIV-No_range + 1 ) ) ).
CATCH CX_ROOT.
  Message 'Error'.
ENDTRY.

Cheers,

Kothand

0 Kudos

Kothand,

Your guess is true.I am facing the problem while calculating the field wa_nriv-M_dooms.

I don't need to show any message to user.Is there any possibility to overcome the issue.

Thanks,

0 Kudos

Hi,

Overcome the error? SAP will not support division by zero as well as infinity value cannot be handled in SAP.

If you dont want anything to happen if the case is division by zero, then leave the program without Message like,


TRY.

wa_nriv-M_dooms = 50 / ( ( ( wa_nriv-currentnumber - wa_nriv-minnumber + 1 ) / ( wa_nriv-No_range + 1 ) )
 
      / ( 1 - ( wa_nriv-currentnumber - WA_NRIV-minnumber + 1 ) / ( WA_NRIV-No_range + 1 ) ) ).

CATCH CX_ROOT.
*   Do Nothing

ENDTRY.

So that the value of wa_nriv-M_dooms will be zero in case of division be zero. I think this can avoid the dump.

Cheers,

Kothand

0 Kudos

Hi Swetha,

Use Below Code

Types: begin of ty_nriv,

OBJECT type NROBJ,

SUBOBJECT type NRSOBJ,

NRRANGENR type NRNR,

TOYEAR type NRYEAR,

minnumber type NRFROM,

maxnumber type NRto,

CurrentNumber type NRLEVEL,

No_range type NRTO,

useage type P decimals 6,

M_dooms type P decimals 4,

end of ty_nriv.

data:g_object type nriv-object,

tab_nriv type standard table of TY_nriv ,

WA_NRIV TYPE TY_NRIV,

GV_YEAR(4) TYPE N .

data:c type P decimals 6,

d type P decimals 6.

*selection screen

select-options: s_object for g_object .

*start-of-slection.

select OBJECT

SUBOBJECT

NRRANGENR

TOYEAR

FROMNUMBER

tonumber

NRLEVEL

from nriv

into table tab_nriv

where object in s_object

and TOYEAR < sy-datum+(4).

loop at tab_nriv into wa_nriv.

WA_NRIV-No_range = WA_NRIV-maxnumber - WA_NRIV-minnumber + 1 .

if wa_nriv-no_range is not initial.

wa_nriv-useage = ( ( wa_nriv-currentnumber - wa_nriv-minnumber + 1 ) /

WA_NRIV-No_range ) * 100 .

endif.

if wa_nriv-No_range <> -1.

c = ( ( wa_nriv-currentnumber - wa_nriv-minnumber + 1 ) / (

wa_nriv-No_range + 1 ) ).

endif.

if c <> 1.

d = ( c / ( 1 - c ) ).

endif.

if d is not initial.

wa_nriv-M_dooms = 50 / d.

endif.

modify tab_nriv from wa_nriv transporting No_range useage M_dooms.

endloop.

Regards

jana