02-21-2008 9:27 AM
i need to handle exception for below code. PLS HELP ME.
when i trying for error records it ll got to dump
IF itab_zdfkkwoh IS NOT INITIAL.
INSERT zdfkkwoh FROM TABLE itab_zdfkkwoh.
IF SY-SUBRC = 0.
DESCRIBE TABLE itab_zdfkkwoh LINES countb.
ELSE.
ENDIF.
*???????
ENDIF.
Edited by: Alvaro Tejada Galindo on Feb 21, 2008 4:33 PM
02-21-2008 10:07 AM
Hi,
you can make to popup a message relavently.
IF <variable> is NOT INITIAL.
INSERT <table> FROM TABLE <itab>.
IF sy-subrc = 0. "data inserted successfully
DESCRIBE TABLE...
ELSE. "data not inserted
MESSAGE 'table insertion error' TYPE 'I'.
ENDIF.
ENDIF.
<REMOVED BY MODERATOR>
teja
Edited by: Alvaro Tejada Galindo on Feb 21, 2008 4:33 PM
02-21-2008 10:07 AM
Hi,
you can make to popup a message relavently.
IF <variable> is NOT INITIAL.
INSERT <table> FROM TABLE <itab>.
IF sy-subrc = 0. "data inserted successfully
DESCRIBE TABLE...
ELSE. "data not inserted
MESSAGE 'table insertion error' TYPE 'I'.
ENDIF.
ENDIF.
<REMOVED BY MODERATOR>
teja
Edited by: Alvaro Tejada Galindo on Feb 21, 2008 4:33 PM
02-21-2008 11:04 AM
Hi,
1. If you wish to handle the exception as an information message,then it will show as a popup window.On closing this window,you can proceed with the program as in a normal flow.To achieve this,you can write the following piece of code :
IF itab_zdfkkwoh IS NOT INITIAL.
INSERT zdfkkwoh FROM TABLE itab_zdfkkwoh.
IF sy-subrc = 0. " Data inserted successfully
DESCRIBE TABLE itab_zdfkkwoh LINES countb.
ELSE. " Data insertion failed
message i001(00) with 'Row(s) with same primary key already exists'.
ENDIF.
ELSE. " Table is initial
message i001(00) with 'Table contains no data'.
ENDIF.
2. However,if you want to raise the exception as an error message,then it will show at the bottom of the screen as a highlighted red field.If you don't rectify the error,the program won't proceed.To achieve this,just make the modification in the message text as :
-
message e001(00) with 'Row(s) with same primary key already exists'.
-
3. If you are writing this piece of code inside a function module,then you can raise exception as :
IF itab_zdfkkwoh IS NOT INITIAL.
INSERT zdfkkwoh FROM TABLE itab_zdfkkwoh.
IF sy-subrc = 0. " Data inserted successfully
DESCRIBE TABLE itab_zdfkkwoh LINES countb.
ELSE. " Data insertion failed
RAISE insertion_error.
ENDIF.
ELSE. " Table is initial
RAISE no_data.
ENDIF.
Here,'insertion_error' & 'no_data' are 2 exceptions that you need to define in the exceptions tab of funtion module definition.They will have sy-subrc values as 1 & 2(if no other exception is defined).
You can handle this exceptions when you call the function module.At the end of function module code,write as :
case sy-subrc.
when 0.
Proceed further
when 1.
insertion_error is raised.Handle the error.*
message i001(00) with 'Row(s) with same primary key already exists'.
when 2.
no_data raised.*
message i001(00) with 'Table contains no data'.
endcase.
Hope this helps.
Regards,
Kaveri.