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.

Be the first to leave a comment

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

Leave a Reply