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

Best Practice: Class Based Exception Handling - differentiate by Exception Text ID

michael_dohse2
Explorer
0 Likes
1,690

Hi folks,

because I did not find a good explanation somewhere, I will just ask you for your experiences or better: Best practices:

Scenario: I created ABAP OO application, including a ZCL_VALIDATOR for some input checks.  I have a Exception class ZCX_VALIDATOR, which has several TextIDs for the different checks in ZCL_VALIDATOR.

Now, a classic SAP Dynpro should call my application, give some input

like:


DATA lo_validator type ref to ZCL_VALIDATOR.

try.

     lo_validator->CHECK_MATNR( iv_matnr = lv_matnr )

catch EXCEPTION TYPE ZCX_VALIDATOR into DATA(lo_exc).

endtry.

Check_matnr does several checks and raises ZCX_VALIDATOR, but dependent on the error case, the GUI should show a 'E' or 'I'.

My approach would be like:


DATA lo_validator type ref to ZCL_VALIDATOR.

try.

     lo_validator->CHECK_MATNR( iv_matnr = lv_matnr )

catch EXCEPTION TYPE ZCX_VALIDATOR into DATA(lo_exc).

if lo_exc->textid-msgid eq 'abc'.

     MESSAGE type lo_exc DISPLAY LIKE 'I'

else.

     MESSAGE type lo_exc DISPLAY LIKE 'E'.


endtry.

Question: Is there any other way to to this?

Thanks for your thoughts on this.

Greetings

michael

Hi folks,

because I did not find a good explanation somewhere, I will just ask you for your experiences or better: Best practices:

Scenario: I created ABAP OO application, including a ZCL_VALIDATOR for some input checks.  I have a Exception class ZCX_VALIDATOR, which has several TextIDs for the different checks in ZCL_VALIDATOR.

Now, a classic SAP Dynpro should call my application, give some input

like:


DATA lo_validator type ref to ZCL_VALIDATOR.

try.

     lo_validator->CHECK_MATNR( iv_matnr = lv_matnr )

catch EXCEPTION TYPE ZCX_VALIDATOR into DATA(lo_exc).

endtry.

Check_matnr does several checks and raises ZCX_VALIDATOR, but dependent on the error case, the GUI should show a 'E' or 'I'.

My approach would be like:


DATA lo_validator type ref to ZCL_VALIDATOR.

try.

     lo_validator->CHECK_MATNR( iv_matnr = lv_matnr )

catch EXCEPTION TYPE ZCX_VALIDATOR into DATA(lo_exc).

if lo_exc->textid-msgid eq 'abc'.

     MESSAGE type lo_exc DISPLAY LIKE 'I'

else.

     MESSAGE type lo_exc DISPLAY LIKE 'E'.


endtry.

Question: Is there any other way to to this?

Thanks for your thoughts on this.

Greetings

michael

3 REPLIES 3
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,029

My point of view is that exceptions should be only used for technical exceptions, not functional validations. Those messages should be collected by "message collectors". Consequently, your question wouldn't need to be asked.

Read only

0 Likes
1,029

Hi Sandra,

thanks for your answer. But how to return from method? by bapiret2 or abap_bool?

greetings

michael

Read only

0 Likes
1,029

Any internal table for collecting messages. BAPIRET2 for instance ; use it for keeping things simple. The best would be to have an official message collector class but I don't know any standard good one. There are BAL_* function modules. There are unreleased ones: function modules MESSAGES_*, MSG_*, BAL_*, in SAP ERP there is class CL_RECA_MESSAGE_LIST...