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?
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 typeMMPUR_BOOL
. In all my other methods I can then set this flag on failure:Finally, my
CHECK
method contains onlych_failed
is taken back to function moduleMEREQBADI_CHECK
which is in turn used in theis_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.