Invalidating line of Purchase Requisition through ME_PROCESS_REQ_CUST

6.3k views Asked by At

I'm trying to prevent a user from saving a Purchase Requisition through a BAdI implementation, checking lines and accounts. The error messages I throw do not stop the saving process, and I can't find a way to invalidate the line, as I would in PO's. So, a PR can be saved containing faulty data.

I extended the purchase requisition BAdI and implemented IF_EX_ME_PROCESS_REQ_CUST in ZCL_IM_EI_PROCESS_REQ_CUST. In methods PROCESS_ITEM and PROCESS_ACCOUNT I have access to several imports on account and item. Unlike the PO though, I can't find a way to invalidate an item. None of the classes used offer that functionality.

The PR item objects I have access to in the BAPI are of interface IF_PURCHASE_REQUISITION_ITEM, implemented as a local class in function pool MEREQ. This interface has a method IS_VALID but does not offer anything to invalidate, in contrast to the PO item interface, which has an INVALIDATE method.

edit

After more debugging it seems the invalidation is done through member MY_STATE-BROKEN_RULES from local class MEREQ/LCL_REQ_ITEM. Any idea how I can access this?

2

There are 2 answers

0
Jorg On BEST ANSWER

As @vwegert suggested, the trick was using the CHECK method. It gets called in the validation methods on the PR.

My solution was to add a member attribute FAILED of type MMPUR_BOOL. In all my other methods I can then set this flag on failure:

IF your condition fails
  me->failed = mmpur_yes.
ENDIF.

Finally, my CHECK method contains only

ch_failed = me->failed.

ch_failed is taken back to function module MEREQBADI_CHECK which is in turn used in the is_valid methods of the PR classes. This invalidates the PR and triggers the messages box you see with standard errors. Custom error message in the image below, on save.

enter image description here

6
Nelson Miranda On

I've done it using MESSAGE 'My message' TYPE 'E' in the 'PROCESS_HEADER' method.

METHOD IF_EX_ME_PROCESS_REQ_CUST~PROCESS_HEADER.
DATA : it_items        TYPE mmpur_requisition_items,
       wa_item         TYPE mmpur_requisition_item,
       wa_item_data    TYPE mereq_item,
       wa_header_data  type mereq_header.

    it_items = im_header->GET_ITEMS( ).      " Purchase requisition positions
    wa_header_data = im_header->GET_DATA( ). " Header info

    LOOP AT it_items INTO wa_item.                      
      CLEAR wa_item_data.  
      wa_item_data = wa_item-item->GET_DATA( ).

      IF wa_item_data-loekz IS NOT INITIAL.
        MESSAGE 'Raise error' TYPE 'E'.
      ENDIF.
    ENDLOOP.
ENDMETHOD.

Hope it helps.