This example demonstrates how to create a global exception class and use it in an ABAP report.
An exception class is created in the class builder SE24. Remember to use Exception Class as Class Type.
The name of a customer developed exception class must always be prefiexed with CX_ (Or YCX_).
You must also choose an exception superclass for the exception class e.g.CX_STATIC_CHECK. This means that the compiler checks if the exception is declared the interface in case it is not handled locally.
1. Start SE 24 and create a new exception class named ZCX_CL_KUNDER_EXCEPTIONS.
2. Go to the text tab and create the exception ID NO_ENTRIES_FOUND and enter the text No entries found for the ID. Note that there are allready som ID that are defined automatically when the class is created:
3. Go to the attributes screen an notice that NO_ENTRIES_FOUND has been automatically added to the attributes:
4. Activate the class
REPORT zhfr_tmp .
DATA: ex TYPE REF TO zcx_cl_kunder_exceptions,
mes TYPE string,
t TYPE i.
TRY.
t = 1.
IF t > 0. "Dummy test, just to raise the exception
RAISE EXCEPTION TYPE zcx_cl_kunder_exceptions EXPORTING textid =
zcx_cl_kunder_exceptions=>no_entries_found.
ENDIF.
CATCH zcx_cl_kunder_exceptions INTO ex.
mes = ex->get_text( ).
MESSAGE mes TYPE 'I'.
ENDTRY.
Result when you run the program:
| Converted from CHM to HTML with chm2web Standard 2.7 (unicode) |