Skip to Content

There are several open questions to be found in scn regarding this topic:
In the BAdI IF_EX_ME_PROCESS_REQ_CUST you can raise custom messages. In some cases, it is desirable to delete these custom messages again. After several tries I finally found a way how to do it.

Example scenario:
all items in a purchase requisition should have the same account assignment category. If not, I issue a custom message in the method process_accoung telling the user that different categories are being used. In case the items are changed by the user in a way that this problem is solved (all account assignment categories are the same) the custom messages generated earlier should be deleted from the message log.

Sample coding of method IF_EX_ME_PROCESS_REQ_CUST~PROCESS_ITEM:

data: ls_item_mereq TYPE MEREQ_ITEM.

data: lv_knttp type knttp.

data: lt_items type MMPUR_REQUISITION_ITEMS.
data: ls_item_next type MMPUR_REQUISITION_ITEM.

data: ls_header TYPE REF TO IF_PURCHASE_REQUISITION.
data: lo_item_next type ref to if_purchase_requisition_item.
data: ls_item_next_mereq type MEREQ_ITEM.

data: lt_events type MMPUR_EVENT_LIST.
data: ls_event type MMPUR_EVENT_ENTRY.
data: lo_business_object type ref to if_message_obj_mm.

INCLUDE mm_messages_mac.

* cv_failed is an attribute of the class indicating
* whether it should be possible to save the purchase
* requisition (will be moved to ch_failed in the method check)
clear cv_failed.

* get item data
ls_item_mereq = im_item->get_data( ).
lv_knttp = ls_item_mereq-knttp.

*     compare with the other items
*     get item data of the other items
ls_header = im_item->GET_REQUISITION( ).
lt_items = ls_header->GET_ITEMS( ).

loop at lt_items into ls_item_next.

*     get object
lo_item_next = ls_item_next-ITEM.

*     only check items other than the current one
if lo_item_next <> im_item.

*         get item data

ls_item_next_mereq = lo_item_next->get_data( ).

*         different account assignment, issue message
if lv_knttp <> ls_item_next_mereq-knttp.

*         set context (has e.g. the value ‘092’) so that this message
*         can be identified later on
mmpur_context CC_MESSAGE_ACCOUNTING.

mmpur_message_forced ‘I’ ‘Z_MM_PUR’ ‘010’ ” ” ” ”.

CV_failed = ‘X’.
endif.
endif.

*   Cleanup messages if needed
*   error was eliminated
if cv_failed is initial.
call method cl_message_handler_mm=>get_handler
importing
ex_handler = gl_message_handler.

*     get all messages

call method gl_message_handler->getlist
importing
EX_EVENTS = lt_events.

*     loop through messages
loop at lt_events into ls_event.

*     check context
if ls_event-context = CC_MESSAGE_ACCOUNTING.

*     remove message
lo_business_object = ls_event-BUSINESS_OBJ.
call method gl_message_handler->REMOVE_BY_BO
EXPORTING
IM_BUSINESS_OBJ = LO_BUSINESS_OBJECT
IM_CONTEXT = ls_event-context.
endif.
endloop.
endif.
endloop.

To report this post you need to login first.

1 Comment

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

  1. Daniel Almeida

    Hi!

    i Had exactly the same problem like you, after the issue was solved i couldn´t make the error messages desapear.

     

    I was using IF_EX_ME_PROCESS_REQ_CUST~CHECK and solved it with the following piece of code:

     
    
     DATAl_msg_handler TYPE REF TO cl_message_handler_mm,
           l_event       TYPE REF TO cl_event_mm,
           lt_event_list TYPE mmpur_event_list,
           re_conf       TYPE melog_s_handler_config.

    " 1)  At the beggining of the code, get the list of messages 
    
    
        CALL METHOD cl_message_handler_mm=>get_handler
          IMPORTING
            ex_handler l_msg_handler.
    
        CALL METHOD l_msg_handler->getlist
          IMPORTING
            ex_events lt_event_list[].
    
    "2) Delete all messages that were already deleted or are expired      CALL METHOD l_msg_handler->get_configuration       RECEIVING         re_configuration re_conf.     re_conf-keep_deleted_events space.     CALL METHOD l_msg_handler->set_configuration       EXPORTING         im_configuration re_conf.

    And that’s it! all error or warning messages that were already solved get deleted…. i found this solution from a Russian forum, the link is below

    https://sapboard.ru/forum/viewtopic.php?t=18975&highlight=mmpur*

    if somebody else is reading this post and has a better solution, please let us know….

    Best Regards!

    (0) 

Leave a Reply