‎2007 May 18 6:34 AM
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
‎2007 May 18 6:36 AM
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
‎2007 May 18 6:37 AM
Hi Santhosh,
Check this sample code to avoid run time error,
*--
*DATA : VALUE1 TYPE I.
*
*VALUE1 = 1 / 0. -
>>>>>> IT MAKES RUN TIME ERROR.
*
*WRITE : VALUE1.
*--
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.
‎2007 May 18 6:39 AM
this case is a conversion error under the error class CONVERSION_ERRORS
CATCH SYSTEM-EXCEPTIONS convt_no_number = 1.
WRITE a .
ENDCATCH.
Regards
Gopi
‎2007 May 18 6:41 AM
hi
good
you can use Sy-msg and sy-subrc to give a message if the condition wont work.
thanks
mrutyun^
‎2007 May 18 6:42 AM
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
‎2007 May 18 6:43 AM
‎2007 May 18 7:14 AM
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