Exception Class To Use Messages From T100
Exception Class To Use Messages From T100
from T100
By Naimesh Patel | April 2, 2013 | Exceptions | 26,581 | 13
Exception class can be defined using to use static Text as well as the messages from the
Message repository maintained using transaction SE91. In this article, lets see how to use
the message from Message repository T100.
As soon as you add the interface, the parameters of the method CONSTRUCTOR would be
adjusted. The TEXTID field is not more referring to the field TEXTID. It would now refer to
the type of the field IF_T100_MESSAGE=>T100KEY. So, when you raise an exception, you
can simply populate the fields of the key and they would be propagated back to the place
where exception would be caught.
Exception ID Constant
CONSTANTS:
BEGIN OF ZCX_MSG_T100,
msgid TYPE symsgid VALUE '00',
msgno TYPE symsgno VALUE '398',
attr1 TYPE scx_attrname VALUE 'IV_FIELD1',
attr2 TYPE scx_attrname VALUE ",
attr3 TYPE scx_attrname VALUE ",
attr4 TYPE scx_attrname VALUE ",
END OF ZCX_MSG_T100 .
The added public attribute, which you have used is also available as one of the parameter
in the CONSTRUCTOR. This would let you assign a specific value to that attribute while
raising the exception. Thus you can propagate that value
back the catcher of the exception.
Complete Public section of the Exception Class looks like this:
INTERFACES IF_T100_MESSAGE .
CONSTANTS:
BEGIN OF ZCX_MSG_T100,
msgid TYPE symsgid VALUE '00',
msgno TYPE symsgno VALUE '398',
attr1 TYPE scx_attrname VALUE 'IV_FIELD1',
attr2 TYPE scx_attrname VALUE ",
attr3 TYPE scx_attrname VALUE ",
attr4 TYPE scx_attrname VALUE ",
END OF ZCX_MSG_T100 .
DATA IV_FIELD1 TYPE CHAR10 .
METHODS CONSTRUCTOR
IMPORTING
!TEXTID LIKE IF_T100_MESSAGE=>T100KEY OPTIONAL
!PREVIOUS LIKE PREVIOUS OPTIONAL
!IV_FIELD1 TYPE CHAR10 OPTIONAL .
Demo
A small Demo to see it in action:
*&---------------------------------------------------------------------*
*& Purpose - Object Oriented Implementation for a Report
*& Author - Naimesh Patel
*& URL - http://zevolving.com/?p=2040
*&---------------------------------------------------------------------*
REPORT ZTEST_NP_T100_EXCEPTION.
*
DATA: lo_exc TYPE REF TO zcx_msg_t100.
DATA: ls_t100_key TYPE scx_t100key.
*
START-OF-SELECTION.
* no message id, would take default ID
* No additional parameter, message would be empty
TRY.
RAISE EXCEPTION TYPE zcx_msg_t100.
CATCH zcx_msg_t100 INTO lo_exc.
MESSAGE lo_exc TYPE 'I'.
ENDTRY.
*
* Specific message ID, with parameter set
TRY.
RAISE EXCEPTION TYPE zcx_msg_t100
EXPORTING
textid = zcx_msg_t100=>ZCX_MSG_T100
IV_FIELD1 = 'Value1'.
CATCH zcx_msg_t100 INTO lo_exc.
MESSAGE lo_exc TYPE 'I'.
ENDTRY.
*
* Raising with a different message
TRY.
ls_t100_key-msgid = '00'.
ls_t100_key-msgno = '443'.
RAISE EXCEPTION TYPE zcx_msg_t100
EXPORTING
textid = ls_t100_key.
CATCH zcx_msg_t100 INTO lo_exc.
MESSAGE lo_exc TYPE 'I'.
Tags