Skip to Content

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
      ).
To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

    1. Kavindra Joshi Post author

      Hi Chirag,

      The blog was written long time back.Essentially i have removed few messages.You can execute the loop and delete all messages.Try this approach and let me know or else look for a delete_message method as well.

      (0) 
  1. Mandeepak Grover

    This code is helpful, it works well if use one more line of code.

    lr_message_service->collect_messages( IV_MESSAGE_TYPE = ‘I’ IV_DELETE_READ_MESSAGES = abap_true ).

    Actually, apart from <lt_message>, there is one more table APPL_MESSAGE_TAB in lr_message_service from where message should also be deleted. And if you call method ‘collect_messages’ as I have mentioned above, it will delete the message from table APPL_MESSAGE_TAB also. As per above code listing, add this method call between 20th and 21st line.

    Thanks..!

    (0) 
    1. Kavindra Joshi Post author

      Hi Mandeepak ,

      Thanks for commenting. Wrote the blog sometime back and I remember considering the possibilities but for some reason or some scenario which I had at that point of time , I did not go with the points you mentioned. Any way solved my problem and hopefully your way solved your problem as well.

      ~Kavindra

      (0) 
      1. Fabien Turcotte

        So from what I could find, there is no other way than code if we want to remove specific messages in the UI?


        I have the requirement to display warnings and errors only, not the Information messages (like mentioned they mean nothing for end users most of the time). There is no other way to remove them?

        (0) 

Leave a Reply