How to remove custom messages in IF_EX_ME_PROCESS_REQ_CUST
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.
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.
* 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)
* 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_message_forced ‘I’ ‘Z_MM_PUR’ ‘010’ ” ” ” ”.
CV_failed = ‘X’.
* Cleanup messages if needed
* error was eliminated
if cv_failed is initial.
call method cl_message_handler_mm=>get_handler
ex_handler = gl_message_handler.
* get all messages
call method gl_message_handler->getlist
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
IM_BUSINESS_OBJ = LO_BUSINESS_OBJECT
IM_CONTEXT = ls_event-context.
Would you like to access Full Article?
If you are already a member in this website, Please Click here to loginIf you are not yet a member, Please Click here to Sign up
New NetWeaver Information at SAP.com