‎2010 Feb 05 5:40 AM
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
‎2010 Feb 05 12:57 PM
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
‎2010 Feb 05 7:46 AM
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.
‎2010 Feb 05 12:57 PM
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
‎2010 Feb 05 1:08 PM
Hello Clemens,
Could you explain in details may be with an example.
thank you.
with regards,
sandeep akella.
‎2010 Feb 06 12:29 AM
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.
ENDTRYThis is the very simplified version without log objects - that would go beyond the limit...
Regards,
Clemens
‎2010 Feb 08 6:14 AM
Hello Clemens,
Thank you for the solution. It solved my problem.
With regards,
sandeep akella