Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ME_PROCESS_REQ_CUST~PROCESS_ITEM validation

Former Member
0 Likes
2,830

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

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,736

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

7 REPLIES 7
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,737

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

Read only

0 Likes
1,736

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?

Read only

0 Likes
1,736

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

Read only

0 Likes
1,736

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?

Read only

0 Likes
1,736

Hi

Something like this:

 DATA: L_VALID TYPE MMPUR_BOOL.

  IM_ITEM->IS_VALID( RECEIVING RE_VALID = L_VALID  ).

Max

Read only

0 Likes
1,736

Hello

Method IS_VALID just returns the current status of the item.

Regards

Uwe

Read only

0 Likes
1,736

You are absolutely right, SAP's note in incorrect.. either that or I need to implement another.

Thanks for the help