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: 

Overflow when converting from "1.09425e+11"

Former Member
0 Kudos

Hi Everyone,

this is an urgent issue, I have certains whose datatype is Packed decimal.

For certain numerical calculations i.e to calculate the variable to the power of 30 and power of 365 it throws up this abap runtime error.

All the variables have declared as packed decimal with 2 decimal places.

How can I fix this issue. Can anyone help me please,

Its really urgent.

Thanks in advance,

Prashant.

1 ACCEPTED SOLUTION

abdul_hakim
Active Contributor
0 Kudos

hi kumar,

for performing scientific operations like power etc it is alwayz prefer to use type f instead of type p.so jus replace all your type p with type f.

Cheers,

Abdul Hakim

Mark all useful answers..

17 REPLIES 17

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Is changing the variables to a float out of the question?

Regards,

Rich Heilman

abdul_hakim
Active Contributor
0 Kudos

hi kumar,

for performing scientific operations like power etc it is alwayz prefer to use type f instead of type p.so jus replace all your type p with type f.

Cheers,

Abdul Hakim

Mark all useful answers..

0 Kudos

Hi,

I'm displaying the results in the form of percentage, so using floating point makes the result look a bit not so good.

Any suggestions please do let me know.

thanks,

Prashant.

0 Kudos

hi kumar,

you cannot achive matissa and exponent scenario with type p you should you type f...

Cheers,

Abdul Hakim

Mark all useful answers..

0 Kudos

Prashant,

as the guys have said, to stop overflow you're going to have to use float internally.

You could move this number to a char variable and then split it into the exponent and mantissa and then construct a display variable from these components. But even 2 ** 365 is 7.515336264876E+109 which means to show it as a character string will almost fill an average report line, and I think most users will not find looking at that very nice either.

The reality is you're dealing with huge numbers and the best way to represent them is the exponential style.

Another thing you could do is set overflow numbers to the biggest number available in the packed format.

eg, something like

CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 1.

result = a ** b.

ENDCATCH.

  • if there is overflow...

IF sy-subrc = 1.

  • it must be..

result = c_max_value.

ENDIF.

0 Kudos

Hi Everyone,

As you have suggested, if it is a large number i try to catch the exception as u have said, but it does not catch instead throws the same abap runtime error.

Here is the sample code, where i am catching the exception.

CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 1.

a = b * 365.

ENDCATCH.

IF sy-subrc = 1.

a = max_value.

ENDIF.

Any help will be of great use to me.

Thanks,

Prashant.

0 Kudos

Prashant,

how are a and b declared and what values do they have?

exactly what runtime error are you getting?

and how is max_value declared? If this is bigger than the allowed amount in 'a' then this will cause the overflow itself! Max_value has to be set to no more than the biggest number that 'a' can hold.

0 Kudos

Hi,

I declared it maxvalue as type f. but still i get the overflow error.

How do else i try and catch this exception.

It throws me the same overflow error. it is not catching the exception.

Any help will be of great use to me its really urgent.

Thanks,

Prashant.

0 Kudos

Prashant - are you saying that your final percentage is 1.09425e+11, or is at intermediate number?

Rob

0 Kudos

Hi,

Within the catch and endcatch block, I have assigned the maxvalue to a, and declared this max value as type f.

For that its not catching the exception. instead again it throws the runtime overflow error.

I was to capture this exception and in the result i want to assign some string saying maxvalue if the value is huge i.e overflowing.

Any help will be appreciated.

Thanks,

Prashant.

0 Kudos

Hi,

Try using within

Try ...ENDTRY.

<b> 
  TRY.
     .........try ur logic.
    CATCH cx_ai_system_fault . " ur exception name 
          WRITE 😕 o_fault->errortext.
  ENDTRY.</b>

0 Kudos

Prashant,

max_value HAS TO BE TYPE P. If it is type F with a bigger value than type P can hold THEN OF COURSE IT WILL OVERFLOW.

The overflow you are now getting is not within the catch but on the 'a = max_value' statement.

eg this works,

data a(15) type p.

data b(15) type p value 20000000000000.

data max_value(15) type p value 999999999999

CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 1.

a = b ** 365.

ENDCATCH.

IF sy-subrc = 1.

a = max_value.

write:/ sy-subrc,a.

endif.

0 Kudos

Hi,

you can try this ....

i just added to Neils suggestion....

changed the EXCEPTION name.


data a(15) type p.
data b(15) type p value 20000000000000.
data max_value(15) type p value 999999999999.

CATCH SYSTEM-EXCEPTIONS <b>COMPUTE_POW_RANGE</b> = 1.
a = b ** 365.
ENDCATCH.
IF sy-subrc = 1.
a = max_value.
write:/ sy-subrc,a.
endif.

Regards

vijay

Former Member
0 Kudos

Hey Guys,

See As how u have suggested I have given the code but still it doesn't pop up a message based on the checkbox.

I perform this only when a checkbox for year is pressed and based on this I have to pop up a message saying it is huge cannot be displayed and get back to the screen. how to I achieve this.

Any help will of great use to me.

if year = 'X'.

CATCH SYSTEM-EXCEPTIONS COMPUTE_POW_RANGE = 1.

a = b ** 365.

ENDCATCH.

IF sy-subrc = 1.

a = max_value.

MESSAGE a001.

ENDIF.

0 Kudos

Do not issue an 'A'bend message. Try issusing a 'W'arning message.

MESSAGE w001

0 Kudos

Also, see what exception you are getting in your runtime dump and use that exception.

0 Kudos

Prashant, the 'A' type message forces an abend. Change it to an 'I' which will op it up in a seperate box or an 'S' mesaage which will just show it at the bottom of the next screen you show.

Also, did you try 'arithmetic error'. Why did you use compute_pow_range?