Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
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.
2 Comments
daniel_almeida88
Explorer

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!

Phil_M
Newcomer
0 Kudos

To Add Messages to the Message Handler:

Create a Method that you can call with the Error Message Variables, sy-msgty, sy-msgid…..  make the input parameters for Message Variables Strings so you can pass pretty much anything in then move them to standard message variables.

 =============================

This will log the message and the system will use it, works great for CHECK Badi, for the PROCESS_ACCOUNT, you may want to post a message directly to the Screen use this Macro in the Method : IF_EX_ME_PROCESS_REQ_CUST~PROCESS_ACCOUNT, when you return a flag your validation failed, make sure you have called   mmpur_message_forced  or you have to set the Syst variables to display the message.

INCLUDE mm_messages_mac.

DATA
lv_message_v1 TYPE symsgv,
lv_message_v2 TYPE symsgv,
lv_message_v3 TYPE symsgv,
lv_message_v4 TYPE symsgv.

IF iv_message_1 IS SUPPLIED.
lv_message_v1 iv_message_1.
ENDIF.
IF iv_message_2 IS SUPPLIED.
lv_message_v2 iv_message_2.
ENDIF.
IF iv_message_3 IS SUPPLIED.
lv_message_v3 iv_message_3.
ENDIF.
IF iv_message_4 IS SUPPLIED.
lv_message_v4 iv_message_4.
ENDIF.

mmpur_message_forced  iv_message_type
iv_message_id
iv_message_number
lv_message_v1
lv_message_v2
lv_message_v3
lv_message_v4.

===========================

To Diplay Messages to the Screen after having used the above in your validation routine to log the error, use this macro:

include MM_MESSAGES_MAC.

mmpur_message symsgty
symsgid
symsgno
symsgv1
symsgv2
symsgv3
symsgv4.

=====================================

To Clear out the Messages, in either CHECK badi method or PROCESS_ACCOUNT (can be slightly adjusted for PROCESS_ITEM, just different Object.

at the begging of the processing for each Account Object, I created a method to reset the Accounting Data Message Logs passing in the Accounting Object.

===========================

METHOD RESET_MESSAGES_FOR_ACCTING_DAT.

INCLUDE mm_messages_mac.

DATAlo_message_handler TYPE REF TO cl_message_handler_mm,
lo_message_object  TYPE REF TO if_message_obj_mm.

CATCH SYSTEM-EXCEPTIONS move_cast_error 1.
lo_message_object ?= io_accounting_data.
ENDCATCH.
IF sysubrc 1.
CLEAR lo_message_object.
RETURN.
ENDIF.

cl_message_handler_mm=>get_handlerIMPORTING ex_handler lo_message_handler ).

mmpur_business_obj lo_message_object.
CALL METHOD lo_message_handler->remove_by_bo
EXPORTING
im_business_obj          lo_message_object
im_include_child_objects abap_true.

ENDMETHOD.

===========================

Phil Munroe

 

Labels in this area