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

customized text messages in class based exceptions

Former Member
0 Likes
1,650

Hello all,

I am using the class based exception to raise SQL query exception using CX_SY_SQL_ERROR.I am using 3 select statements in a method and i am raising the error after checking SY-SUBRC.I am catching the error outside the method.

I want to know from which SQL query has failed..eg:

If the database query was successfull and i did not get records for that input I want to have a customized message like 'No records found in MARA',.

If the database connectivity was lost etc, I will get the messages by reading the message from method GET_TEXT.

etc depending on the query at which exception was raised.

Any suggestion in this regard.

with regards,

sandeep akella.

Edited by: sandeep akella on Feb 5, 2010 6:42 AM

Edited by: sandeep akella on Feb 5, 2010 6:49 AM

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
1,055

Hi Sandeep,

in our project we learned that you will run into trouble if you do not issue a customized message using the message statement.

In error sistuations, we tend to always use a MESSAGE ... INTO DUMMY with DUMMY defined as a string variable. After issuing this dummy message, we raise an exception and/or add the message to a protocol object or issue the mesage directly.

The big advantage is: When users see a message regardless of context we can check the where-used-list and find the error source quickly.

When people started this big project years ago they also worked with get_text methods and then issued generic error messages. Now it is extremely difficult to determine the exact source of the error.

SAP used the way of coding "IF 1 = 2. MESSAGE <ID> <TYPE> <NUMBER>.ENDFIF. just to create a whre-used-list-entry.

I think is is far better to use a MESSAGE INTO DUMMY statement: You create a where-used-lust entry, you can see the full error text in debugger and you can use the SY-MSG++ variables for any subsequent handling.

Regards,

Clemens

5 REPLIES 5
Read only

Former Member
0 Likes
1,055

Hi Sandeep,

i fell the exception class object of CX_SY_SQL_ERROR will not be instantiated if the query fails . Moreover the CX_SY_SQL_ERROR does not have amy attribute idication any table name.

My advise to you is to have a

centralised Z exception class( say zselect_exception) which has attribute TABLE_NAME.

Add a text in the Z excep tion class say NO_DATA_FOUND like 'No data records found in &TABLE_NAME&.

So whenever the data exception fails in your select then use like

raise exception type zselect_exception

exporting text_id = zselect_exception=>NO_DATA_FOUND

table_name = 'MARA'.

So outside the method

You catch the same and use get_text method to get the corresponding message.

Read only

Clemenss
Active Contributor
0 Likes
1,056

Hi Sandeep,

in our project we learned that you will run into trouble if you do not issue a customized message using the message statement.

In error sistuations, we tend to always use a MESSAGE ... INTO DUMMY with DUMMY defined as a string variable. After issuing this dummy message, we raise an exception and/or add the message to a protocol object or issue the mesage directly.

The big advantage is: When users see a message regardless of context we can check the where-used-list and find the error source quickly.

When people started this big project years ago they also worked with get_text methods and then issued generic error messages. Now it is extremely difficult to determine the exact source of the error.

SAP used the way of coding "IF 1 = 2. MESSAGE <ID> <TYPE> <NUMBER>.ENDFIF. just to create a whre-used-list-entry.

I think is is far better to use a MESSAGE INTO DUMMY statement: You create a where-used-lust entry, you can see the full error text in debugger and you can use the SY-MSG++ variables for any subsequent handling.

Regards,

Clemens

Read only

Former Member
0 Likes
1,055

Hello Clemens,

Could you explain in details may be with an example.

thank you.

with regards,

sandeep akella.

Read only

Clemenss
Active Contributor
0 Likes
1,055

Hi Sandeep,

simply..

* implementation
METHOD SELECT
  EXCEPTION TYPE ZX_XYZ.

select ... from mara...
if sy-subrc <> 0.
  message ID ZXY TYPE E NUMBER 123 WITH 'MARA' into mv_dummy.
  raise EXCEPTION TYPE ZX_XYZ..
endif.
select ... from makt...
if sy-subrc <> 0.
  message ID ZXY TYPE E NUMBER 123 WITH 'MAKT' into mv_dummy.
  raise EXCEPTION TYPE ZX_XYZ..
endif.
select ... from mard...
if sy-subrc <> 0.
  message ID ZXY TYPE E NUMBER 123 WITH 'MARD' into mv_dummy.
  raise EXCEPTION TYPE ZX_XYZ..
endif.
ENDMETHOD.

* Program call
TRY.
  select().
  catch  ZX_XYZ.
  message ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDTRY

This is the very simplified version without log objects - that would go beyond the limit...

Regards,

Clemens

Read only

Former Member
0 Likes
1,055

Hello Clemens,

Thank you for the solution. It solved my problem.

With regards,

sandeep akella