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: 

Try catch implementation in dynamic query

Former Member
0 Kudos

I am fetching values by dynamic selection (select a,b,..from (var)...) .

Eveytime if I am selecting garbage value of var it will throw dump . Can u tell me how we implement try catch method / exception handling method so that I can avoid dump in dynamic query

Appropriate answer will rewarded with points that is for sure .

1 ACCEPTED SOLUTION

0 Kudos

Hi,

Check the dump to find the Exception that is being raised.

If it is someting that starts with CX_ then use as follows

TRY.

Your code here.

Catch CX_----- (Exception.

ENDTRY.

If it is not any exception that starts with CX then some of the runtime exceptions cannot be handled with the help of TRY CATCH.

You can also try

CATCH SYSTEM-EXCEPTIONS:

Regards,

Sesh

3 REPLIES 3

0 Kudos

Hi,

Check the dump to find the Exception that is being raised.

If it is someting that starts with CX_ then use as follows

TRY.

Your code here.

Catch CX_----- (Exception.

ENDTRY.

If it is not any exception that starts with CX then some of the runtime exceptions cannot be handled with the help of TRY CATCH.

You can also try

CATCH SYSTEM-EXCEPTIONS:

Regards,

Sesh

0 Kudos

The exception is 'CX_SY_DYNAMIC_OSQL_SEMANTICS',

Can I handle this with catch system-exceptions also ?

Former Member
0 Kudos

Here is the usage of th try statements ...

PARAMETERS number TYPE i. 
DATA: result TYPE p LENGTH 8 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. 

<b>please see this link for detailed explaination of the TRY & ENDTRY ...</b>

<a href="http://">http://help.sap.com/saphelp_nw04/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/content.htm</a>

reward points if it is usefull......

Girish