‎2010 Nov 04 3:29 PM
I wish to implement a validation on this BAdI for transaction ME51N, so that when it fails it should block the transaction (just like a missing required field does)
how can I make the item invalid and raise an error description to the screen?
right now I am just trying to fail for all cases, for example:
method IF_EX_ME_PROCESS_REQ_CUST~PROCESS_ITEM.
data: lv_description(200) type c.
lv_description = 'fails no matter what'.
im_item->FAIL( exporting error = lv_description ).
endmethod.
Can this be done inside this bapi/method?
I have tried using the check method, but
‎2010 Nov 04 3:48 PM
Hello
You need to add include MM_MESSAGES_MAC to your class. Furthermore, you cannot raise errors within a BAdI but collect the error messages. For sample coding see class CL_PO_HEADER_HANDLE_MM:
METHOD po_read.
INCLUDE mm_messages_mac. " <<<
DATA: l_po_number TYPE ekko-ebeln.
IF im_po_number NE space.
l_po_number = im_po_number.
ELSE.
l_po_number = po_number.
ENDIF.
* authority check on transaction code disabled
* If called via CALL TRANSACTION, this check is already done by basis
* (see note 358122)
* restriction of T-code authority check to Enjoy only
IF for_bapi IS INITIAL.
* tcode authorization
IF NOT im_tcode IS INITIAL.
CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
EXPORTING
tcode = im_tcode
EXCEPTIONS
ok = 0
not_ok = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE e172(00) WITH im_tcode INTO gl_dummy.
mmpur_message_forced 'E' '00' '172' im_tcode '' '' ''. " <<<<<
ex_result = mmpur_no.
CALL METHOD set_state( im_state = c_available ).
EXIT.
ENDIF.
ENDIF.
ENDIF.
...
Regards
Uwe
‎2010 Nov 04 3:48 PM
Hello
You need to add include MM_MESSAGES_MAC to your class. Furthermore, you cannot raise errors within a BAdI but collect the error messages. For sample coding see class CL_PO_HEADER_HANDLE_MM:
METHOD po_read.
INCLUDE mm_messages_mac. " <<<
DATA: l_po_number TYPE ekko-ebeln.
IF im_po_number NE space.
l_po_number = im_po_number.
ELSE.
l_po_number = po_number.
ENDIF.
* authority check on transaction code disabled
* If called via CALL TRANSACTION, this check is already done by basis
* (see note 358122)
* restriction of T-code authority check to Enjoy only
IF for_bapi IS INITIAL.
* tcode authorization
IF NOT im_tcode IS INITIAL.
CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
EXPORTING
tcode = im_tcode
EXCEPTIONS
ok = 0
not_ok = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE e172(00) WITH im_tcode INTO gl_dummy.
mmpur_message_forced 'E' '00' '172' im_tcode '' '' ''. " <<<<<
ex_result = mmpur_no.
CALL METHOD set_state( im_state = c_available ).
EXIT.
ENDIF.
ENDIF.
ENDIF.
...
Regards
Uwe
‎2010 Nov 04 4:03 PM
fantastic, error message is now shown, just one more thing to solve the problem:
How can make the item invalid, so as to block the transaction from saving the purchase request? (just raising the error message does not block it)
Or does this depends on which message is called?
‎2010 Nov 04 4:21 PM
Hello
I think if you implement method CHECK (Closing check) and return CH_FAILED = 'X' then the user probably cannot save the PO requisition.
Regards
Uwe
‎2010 Nov 04 6:10 PM
I prefer not to replicate the validation on check if it can be done at the process_item
I've found on note 611175 the following:
If you want to flag the document item as invalid, use method IS_VALID() of interface IF_PURCHASE_REQUISITION_ITEM for this. Do not forget to flag return parameter re_valid as mmpur_rule_invalid.
How can I flag a return parameter?
‎2010 Nov 04 6:34 PM
Hi
Something like this:
DATA: L_VALID TYPE MMPUR_BOOL.
IM_ITEM->IS_VALID( RECEIVING RE_VALID = L_VALID ).
Max
‎2010 Nov 04 6:38 PM
Hello
Method IS_VALID just returns the current status of the item.
Regards
Uwe
‎2010 Nov 05 9:34 AM
You are absolutely right, SAP's note in incorrect.. either that or I need to implement another.
Thanks for the help