Application Development 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: 

Error Handling in ABAP

Former Member
0 Kudos

Dear All,

How to handle errors in ABAP.

Thanks in Advance

Arun

4 REPLIES 4

former_member188685
Active Contributor
0 Kudos

using sy-subrc you can handle the exceptions.

using try catch blocks also you can handle the exceptions.

vijay

former_member188685
Active Contributor
0 Kudos
REPORT ZTEST
PARAMETERS number TYPE i. 
DATA: result TYPE p DECIMALS 2, 
      oref TYPE REF TO cx_root, 
      text TYPE string. 

TRY. 
    IF ABS( number ) > 100. 
      RAISE EXCEPTION TYPE cx_demo_abs_too_large. 
    ENDIF. 
    PERFORM calculation USING    number 
                      CHANGING result 
                               text. 
  CATCH cx_sy_arithmetic_error INTO oref. 
    text = oref->get_text( ). 
  CATCH cx_root INTO oref. 
    text = oref->get_text( ). 
ENDTRY. 

IF NOT text IS INITIAL. 
  WRITE / text. 
ENDIF. 

WRITE: / 'Final result:', result. 

FORM calculation USING    p_number LIKE number 
                 CHANGING p_result LIKE result 
                          p_text   LIKE text 
                          RAISING  cx_sy_arithmetic_error. 

  DATA l_oref TYPE REF TO cx_root. 

  TRY. 
      p_result =  1 / p_number. 
      WRITE: / 'Result of division:', p_result. 
      p_result = SQRT( p_number ). 
      WRITE: / 'Result of square root:', p_result. 
    CATCH cx_sy_zerodivide INTO l_oref. 
      p_text = l_oref->get_text( ). 
    CLEANUP. 
      CLEAR p_result. 
  ENDTRY. 

ENDFORM.

Former Member
0 Kudos

Hi Arun

Error handling is different from excepion handling. An exception is a situation during ABAP program execution in which normal program continuation does not appear to be desirable. Exceptions can be triggered both implicitly and explicitly in the ABAP program.

Here are few useful urls.

Error handling and Debugging concepts

<a href="http://">http://help.sap.com/saphelp_nw04s/helpdata/en/22/043086488911d189490000e829fbbd/frameset.htm</a>

Exception Handling

<a href="http://">http://help.sap.com/saphelp_nw04s/helpdata/en/cf/f2bbc8142c11d3b93a0000e8353423/frameset.htm</a>

I hope this will help. Dont forget to give points, if its worth :).

Regards,

Rakesh

Former Member
0 Kudos

Hi,

There are different causes for ABAP errors, depending on the program.

<b>Causes include:</b>

1. Incorrect or incomplete entries in the RFC destination (transaction SM59)

2. Network problems

3. Authorization problems

4. Error in the RFC program

<b>Error Handling:</b>

Classical ABAP exceptions are raised by <b>RAISED</b> and can be handled by calling methods and function modules using the <b>EXCEPTIONS</b> clause. These exceptions cannot be handled when calling subroutines, instead they are propagated automatically to the next non-subourtinate level.

Some of the exceptions can be caught if the statement that caused the runtime error is placed in a <b>CATCH SYSTEM - EXCEPTIONS</b> block.

<b>MESSAGE</b> statements can also be used to indicate errors.

For Type E or A : can be cought directly by calling methods and function modules using the EXCEPTIONS clause and exception name <b>error_message</b>