There are many times when we override an existing functionality for e.g override standard EH_ONSAVE/EH_ONEDIT etc. but the standard messages are still triggered. These messages don’t make any business relevance any more and have to be removed. If the messages are added to the global message containter or genil level message container then they can be removed easily but the message was added directly using cl_bsp_wc_message_service=>add_message( ) ,and removing the specific message was not happening in my case. I tried many approaches suggested in the SCN , but they did not work hence I had to do the below mentioned.
The following blog , I have written would help you to remove a specific message. This approach looks fine but then if there are side-effects of this please feel to share using the comments in the blog. Actually there could be based on the scenario and I was not able to determine in my case.
For an example I am trying to remove message of class CRM_BOL , message no 003, message type I .
data: lr_message_service type ref to cl_bsp_wd_message_service, ls_genil_message type crmt_genil_message, lt_genil_message type crmt_genil_message_tab, lr_msg type ref to bsp_wd_message_tab. field-symbols: <lt_message> type bsp_wd_message_tab, <ls_message> type bsp_wd_message. lr_message_service = cl_bsp_wd_message_service=>get_instance( ). lr_message_service->get_messages( exporting iv_msg_type = if_genil_message_container=>mt_all " Messages, Message Type * iv_max_lines = " Max. Number of Returned Messages iv_delete_read_messages = abap_true receiving rv_result = lr_msg " Table of Messages ). assign lr_msg->* to <lt_message>. check <lt_message> is assigned. loop at <lt_message> assigning <ls_message> where type = 'I' and id = 'CRM_BOL' and number = '003'. delete <lt_message> index sy-tabix. endloop. unassign <ls_message>. check <lt_message> is assigned. loop at <lt_message> assigning <ls_message>. ls_genil_message-id = <ls_message>-id. ls_genil_message-number = <ls_message>-number. ls_genil_message-type = <ls_message>-type. ls_genil_message-var1 = <ls_message>-var1. ls_genil_message-var2 = <ls_message>-var2. ls_genil_message-var3 = <ls_message>-var3. ls_genil_message-var4 = <ls_message>-var4. ls_genil_message-message = <ls_message>-message. ls_genil_message-dyn_msg_num = <ls_message>-msg_handle. append ls_genil_message to lt_genil_message. endloop. check lt_genil_message is not initial. * Add the remaining messages back to message class lr_message_service->add_messages( exporting it_messages = lt_genil_message " Table of Messages * iv_msg_level = '1' " Message Level ).