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: 

Catch Exception Error

Former Member
0 Kudos
2,407

Is there any way to catch this exception, without checking or changing numerical value.

CATCH SYSTEM-EXCEPTIONS
    convt_no_number = 1
    convt_overflow = 2
    bcd_field_overflow = 3
    bcd_overflow = 4.
 
    DO 10000000000000 TIMES. "<<--Runtime Error-BCD_OVERFLOW (Overflow during an arithmetic operation)
      write:/ sy-index.
    ENDDO.
 
  ENDCATCH.

Regards

Sain

9 REPLIES 9

Former Member
0 Kudos
392

CX_SY_ARITHMETIC_OVERFLOW

it is a catchable exception. put it in a try catch block and this exception class will catch your error

0 Kudos
392
TRY .
      DO  10000000000000 TIMES.
      write:/ sy-index.
      ENDDO.
    CATCH CX_SY_ARITHMETIC_OVERFLOW."CX_SY_CONVERSION_OVERFLOW.

  ENDTRY.

Still same error.

My main intension is to solve this with exception handling.

0 Kudos
392

try this...

data: p1 type p.
  TRY. 
p1 = 10000000000000.
     DO  p1 TIMES.
      write:/ sy-index.
      ENDDO.
    CATCH cx_sy_arithmetic_error.  "outside value range 
  ENDTRY.

0 Kudos
392

oopsi

data: p1 type p.
  TRY. 
p1 = 10000000000000.
     DO  p1 TIMES.
      write:/ sy-index.
      ENDDO.
    CATCH CX_SY_ARITHMETIC_OVERFLOW.  "try both the examples
  ENDTRY.

0 Kudos
392

Dear Mishra,

Thanks for answer.

Try.
p1 = 10000000000000.

this one will work for sure. But I am trying to catch error resulting in a time consuming loop.

Former Member
0 Kudos
392

ook.. got your point.

CATCH SYSTEM-EXCEPTIONS ARITHMETIC_ERRORS = 5.
    DO 10000000000000 TIMES. "<<--Runtime Error-BCD_OVERFLOW (Overflow during an arithmetic operation)
      write:/ sy-index.
    ENDDO.
  ENDCATCH.
ENDCATCH.
IF sy-subrc = 5.
 wrie 'overflow'.
endif.

0 Kudos
392

if this does not work then pass the sy-index + 1 to an integer variable before the enddo.. this should definitely work.

0 Kudos
392

Thanks for quick reply Mishra.

But unfortunately it didn't work.

0 Kudos
392

Hi,

As explained in the ABAP documentation, the number of iterations has to match a I type (integer up to 2 billion). Note: SY-INDEX is also an integer.

What is fun here is that the ABAP runtime environment doesn't apply the CATCH to the conversion overflow when it's done in the DO statement.

If you do this, the exception is handled correctly:


data pack type p length 10 DECIMALS 0.
data integer type i.
CATCH SYSTEM-EXCEPTIONS
    convt_no_number = 1
    convt_overflow = 2
    bcd_field_overflow = 3
    bcd_overflow = 4.
pack = 10000000000000.
integer = pack. "<==== Here exception BCD_OVERFLOW occurs and is handled by the CATCH
    DO integer TIMES.
      write:/ sy-index.
    ENDDO.
  ENDCATCH.

Now, if you want to do a big big loop, you have to accommodate with the system's restriction by using a nested loop:


DATA pack TYPE p LENGTH 8 DECIMALS 0. "up to 15 digits
  DO 1000000 TIMES.
    DO 10000000 TIMES.
      ADD 1 TO pack.
      write:/ pack.
    ENDDO.
  ENDDO.

Sandra