Skip to Content
Technical Articles
Author's profile photo Dzmitryi Kharlanau

How to add a customer-specific check for a purchase order

When we have a customer requirement to implement checks for PO data before saving, we can implement BADI ME_PROCESS_PO_CUST. The check for the fields can be implemented in methods:

  • PROCESS_* (example: PROCESS_ITEM Processing of Item Data )
  • CHECK Closing Check

To raise an error message we use macros. To make them available, specify in the beginning the following include mm_messages_mac.

After the logical condition when the error should be raised:

  • Set the context ( a freely selected number from the range 900-999):  mmpur_context &Context.
  • Set the business object: mmpur_business_obj_id &Object ID.
  • Set the error message from the message class with variables ( message type, message class, message number, message variables 1-4) : mmpur_message_forced  &Message type...
  • Invalidate the object: CALL METHOD invalidate).
  • Set the check failed in case of  Closing Check :   ch_failed abap_true.

If the logical condition, defines that we have no error message, the error message must be removed from the context

  • mmpur_remove_msg_by_context &Object ID &Context .

 

Below you can find example for the closing check of a purchase order.

1) Example of raising an error message at the header level

    IF ls_header-vsart NE 'Z1' AND lv_error EQ abap_true.

      mmpur_context 990.
      mmpur_business_obj_id ls_header-id.
      mmpur_message_forced 'E' 'Z_PO_ERROR' '001' '' '' '' ''.

      CALL METHOD im_header->invalidate( ).
      ch_failed = abap_true.
    ELSE.
      mmpur_remove_msg_by_context ls_header-id 990.
    ENDIF.

2) Example of raising an error message at the iem level

    DATA(lt_items) = im_header->get_items( ).

    LOOP AT lt_items INTO DATA(ls_item).
      lm_items = ls_item-item.

      DATA(ls_mepoitem) = lm_items->get_data( ).
      IF ls_mepoitem-vsart NE 'Z1' AND lv_error EQ abap_true.
        mmpur_context 991.
        mmpur_business_obj_id ls_mepoitem-id.
        mmpur_message_forced 'E' 'Z_PO_ERROR' '002' ls_mepoitem-ebelp '' '' ''.
        CALL METHOD lm_items->invalidate( ).
        ch_failed = abap_true.
      ELSE.
        mmpur_remove_msg_by_context ls_mepoitem-id 991 .
      ENDIF.
    ENDLOOP.

The error message will be shown in the log ( example from Transaction ME22N ):

 

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.