Application Development and Automation 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: 
Read only

Handling Exceptions.

0 Likes
821

Hi,

Is there are any way to Handle Exceptions raised From the 'IF..ENDIF' Statement.

For Example.

<b>data a type i.

CATCH SYSTEM-EXCEPTIONS: conversion_errors = 2.

if a = 'adsdsd'.

write 'dsdfsdf'.

endif.

ENDCATCH.

IF sy-subrc <> 0.

MESSAGE i000msgclass) WITH 'santosh'.

ENDIF..</b>

Please Execute the code...then you will come to know.

Exception is Not Raised.

will definitely Gives Runtime Error.

Points will be rewarded...

Thanks & Regards,

santosh.

Message was edited by:

santosh

7 REPLIES 7
Read only

Former Member
0 Likes
793

Hi,

to avoid that.u have to use try,catch functionality.

have alook at this below link.

http://help.sap.com/saphelp_nw04/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/content.htm

rgds,

bharat.

Message was edited by:

Bharat Kalagara

Read only

Former Member
0 Likes
793

Hi Santhosh,

Check this sample code to avoid run time error,

*--


EXAMPLE FOR RUNTIME ERROR--


*DATA : VALUE1 TYPE I.

*

*VALUE1 = 1 / 0. -


>>>>>> IT MAKES RUN TIME ERROR.

*

*WRITE : VALUE1.

*--


EXAMPLE FOR HOW TO CATCH THE ARITHMETIC ERROR AT THE RUN TIME USING SUBRC--


DATA : VALUE1 TYPE I.

CATCH SYSTEM-EXCEPTIONS ARITHMETIC_ERRORS = 1.

VALUE1 = 1 / 0.

WRITE : VALUE1.

ENDCATCH.

IF SY-SUBRC = 1.

WRITE : ' IT MAKES ERROR'.

ELSE.

WRITE : VALUE1.

ENDIF.

Thanks.

Reward If helpful.

Read only

gopi_narendra
Active Contributor
0 Likes
793

this case is a conversion error under the error class CONVERSION_ERRORS

CATCH SYSTEM-EXCEPTIONS convt_no_number = 1.

WRITE a .

ENDCATCH.

Regards

Gopi

Read only

Former Member
0 Likes
793

hi

good

you can use Sy-msg and sy-subrc to give a message if the condition wont work.

thanks

mrutyun^

Read only

Former Member
0 Likes
793

hi,

If you want to handle the exception then always check the sy-subrc.

if sy-subrc <> 0.

message ' run time error'.

endif.

***do reward if usefull

regards,

vijay

Read only

0 Likes
793

Sory Friends,,

i want to catch the excpetion...

regards,

santosh

Read only

Former Member
0 Likes
793

Hi Santosh

I have analyzed your program. There is one problem with IF-ENDIF block that you have written in CATCH block.You have to directly assign the value first and then use it in any conditional statement.

Also the exception type is <i><b>CONVT_NO_NUMBER</b></i> in your case.

Following is the correct code -

data a type i.

CATCH SYSTEM-EXCEPTIONS: CONVT_NO_NUMBER = 5.
  a = 'adsdsd'.
  IF a = 'adsdsd'.
    a = 'adsdsd'.
  ENDIF.
ENDCATCH.

IF sy-subrc = 5.
  WRITE 'ERROR'.
ENDIF.

As this sort out your query, kindly mark the thread <i><b>Solved</b></i> and close the thread.

Regards