‎2020 May 19 12:22 PM
Good day all. I have created a custom exception class which extends from CX_STATIC_CHECK. Under properties I specified a custom message class under general data in message class field. I want to display the text from the custom message class in the class texts when I throw a message as opposed to specifying the text directly in the class. How do I do that? Thanks in advance.
‎2020 May 19 12:51 PM
Is that what you're looking for ? Or could you clarify your question please?
TRY.
...
CATCH zcx_... INTO DATA(exception).
DATA(text) = exception->GET_TEXT( ).
ENDTRY.
‎2020 May 19 1:09 PM
Hi Sandra. Thanks very much for your help. I've created an exception class and specified a custom message class to be used with that class under properties. If I do this does it mean I don't have to specify any texts or text symbols in the class? Also...how do I throw the exception and specify the appropriate message id from the message class in the textid attribute on raising the exception?
‎2020 May 19 2:01 PM
You do not need to explicitly "reference" the message class you want to consume text from from the exception class. You specify the message at the time when the exception is thrown.
Given you created the exception class with flag With Message Class ticked syntax is
RAISE EXCEPTION TYPE zcx_test MESSAGE e001(zmessages) WITH 'This' 'is' 'a' 'test'.(system release 7.52+) or
DATA textid TYPE scx_t100key.
textid-msgid = 'ZMESSAGES'.
textid-msgno = '001'.
textid-attr1 = 'This'.
textid-attr2 = 'is'.
textid-attr3 = 'a'.
textid-attr4 = 'test'.
RAISE EXCEPTION TYPE zcx_test
EXPORTING
textid = textid.
(also for lower releases)
The message class on the properties tab servers a different purpose.
‎2020 May 19 2:14 PM
CLASS zcx_blabla DEFINITION
PUBLIC
INHERITING FROM cx_static_check
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_t100_dyn_msg .
INTERFACES if_t100_message .
CONSTANTS:
BEGIN OF fail_to_...,
msgid TYPE symsgid VALUE '00',
msgno TYPE symsgno VALUE '398',
attr1 TYPE scx_attrname VALUE 'GV_PARAMETER1',
attr2 TYPE scx_attrname VALUE '',
attr3 TYPE scx_attrname VALUE '',
attr4 TYPE scx_attrname VALUE '',
END OF fail_to_... .
data GV_PARAMETER1 type string.
METHODS constructor
IMPORTING
!textid LIKE if_t100_message=>t100key OPTIONAL
!previous LIKE previous OPTIONAL
iv_parameter1 TYPE string OPTIONAL.
endclass.
class zcx_blabla implementation.
METHOD constructor ##ADT_SUPPRESS_GENERATION.
CALL METHOD super->constructor
EXPORTING
previous = previous.
gv_parameter1 = iv_parameter1.
endmethod.
endclass.
to be able to push parameters to the exception class.
and when you will use it
raise exception type zcx_blabla
exporting
textid = zcx_blabla=>failed_to_...
iv_parameter1 = "whateveryouwant.