‎2007 Jun 11 1:03 PM
Hi!
Pls tell me a sample code in core abap exception handling
ie using raise etc...
one more thing
we can use this try endtry catch endcatch etc without using oops concept in abap.
will it works
looking for your reply.
‎2007 Jun 11 1:08 PM
Hi
See any std fun module in SE37
you will find lot of this statements
TRY.
go_cucb->get_configuration(
EXPORTING
is_instance_version = ls_instance_version
iv_with_db_instance = iv_with_db_instance
iv_head_request = lv_head_request
iv_ref_request = lv_ref_request
IMPORTING
es_cbase = ls_cfg_head
et_configuration = lt_cfg
eo_cbase_ref = eo_cbase_ref ).
MOVE-CORRESPONDING ls_cfg_head TO ibase-conf. "#EC ENHOK
LOOP AT lt_cfg REFERENCE INTO ls_inst_ref.
MOVE-CORRESPONDING ls_inst_ref->* TO ls_ibco_inst. "#EC ENHOK
APPEND ls_ibco_inst TO configuration.
ENDLOOP.
CATCH cx_cbase_error INTO lx_error.
PERFORM raise_exception
USING
lx_error
space.
ENDTRY.
<b>Reward points for useful Answers</b>
Regards
Anji
‎2007 Jun 11 1:11 PM
Hi,
Exceptions are situations that occur while an ABAP program is being executed, in which normal continuation of the program does not make any sense.
Exceptions can be raised either implicitly in the ABAP runtime environment or explicitly in the ABAP program.
For example, division by zero leads to an exception in the ABAP runtime environment. It is possible to determine this situation through a query in the ABAP program and to trigger an exception there.
See the demo program DEMO_HANDLE_EXCEPTIONS in se38.
*--
*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.
in abap program we handle exceptions based on value returned by the system variable SY-SUBRC.
if SY-SUBRC = 0.
means execution completed sucessfull.
if SY-SUBRC = 1........n.
means execution compleated not sucessfully.
if sy-sbrc = 0.
write:/ 'execution sucessfull.
**here write logic as per u r requirement
else sy-subrc = '1'
message
elseif sy-subrc eq '2'
message
elseif sy-subrc eq '3'
message
elseif sy-subrc eq '4'
message
endif
Messages are defined in SE91..
These messages are of 5 types..
<b>A Termination Message</b>
The message appears in a dialog box, and the program terminates. When the user has confirmed the message, control returns to the next-highest area menu.
<b>E Error Message</b>
Depending on the program context, an error dialog appears or the program terminates.
<b>I (Information)</b>
The message appears in a dialog box. Once the user has confirmed the message, the program continues immediately after the MESSAGE statement.
<b>S (Status Message)</b>
The program continues normally after the MESSAGE statement, and the message is displayed in the status bar of the next screen.
<b>W (Warning)</b>
Depending on the program context, an error dialog appears or the program terminates.
<b>X (Exit)</b>
No message is displayed, and the program terminates with a short dump. Program terminations with a short dump normally only occur when a runtime error occurs. Message type X allows you to force a program termination. The short dump contains the message ID.
Pls read the following links:
http://help.sap.com/saphelp_nw04/helpdata/en/fb/35c62bc12711d4b2e80050dadfb92b/content.htm
Regards,
Padmam.