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

Exceptions Handling Programs Needed! Pls!!!

Former Member
0 Likes
396

Hi!

Can any one give some sample programs of how exception handling is done in abap.

Pls send it guys looking for your reply.

rahul.sapabap@gmail.com

Rahul.

1 REPLY 1
Read only

Former Member
0 Likes
350

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.


*-------------------------------------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.

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 5 types..

A Termination Message

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 (nformation)<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.

regards,

Ashokreddy.