05-13-2014 1:02 PM
Hello,
I am using BADi : ZME_PROCESS_PO_CUST~POST, to check if PO creater and PO release(ME29N) person are going to be same. ITs working correctly - but i am not able to throw the error message. Tried various options from SDN, nothing works.
When debugging - it goes to message - but the message is not getting displayed and PR is getting released.
DATA: lv_ernam TYPE ekko-ernam.
IF sy-tcode = 'ME29N'.
SELECT SINGLE ernam INTO lv_ernam FROM ekko
WHERE ebeln = im_ebeln.
IF lv_ernam = sy-uname.
* MESSAGE e000(0k) WITH 'User is not authorized to Release Purchase Order'.
* MESSAGE w000(00) with 'User is not authorized to Release Purchase Order' DISPLAY LIKE 'E'.
* MESSAGE E118(ZMES)." display like 'E'.
* MESSAGE ID 'ZMES' TYPE 'E' NUMBER '118' WITH 'User is not authorized to Release Purchase Order'.
MESSAGE e398(00) WITH ' User is not authorized to Release Purchase Order' .
mmpur_message_forced 'E' 'ME' '118'
ENDIF.
Thanks
Senthil
05-13-2014 1:15 PM
Hi Senthil,
Please try below code with include.
INCLUDE mm_messages_mac.
DATA: lv_ernam TYPE ekko-ernam.
IF sy-tcode = 'ME29N'.
SELECT SINGLE ernam INTO lv_ernam FROM ekko
WHERE ebeln = im_ebeln.
IF lv_ernam = sy-uname.
mmpur_message_forced 'E' 'ME' '118' '' '' '' ''.
ENDIF.
Regards,
Prasenjit
05-13-2014 1:19 PM
05-13-2014 1:25 PM
Hi Senthil,
Are you added include mm_messages_mac in your program on top.? Please add your code in CHECK method not POST method.
I think it will be work because CHECK method having Exception.
Regards,
Prasenjit
05-13-2014 2:03 PM
Hi Senthil,
Try putting the method for error message mentioned by Prasenjit in both CHECK and POST method.
I think the CHECK method will be trigered only for check button and POST for actual save in PR.
Regards
Sree
05-13-2014 1:15 PM
Hi Senthil -
1. Use the method - CHECK.
2. Please include the macro -
INCLUDE mm_messages_mac.
3. To raise the errror, please use following syntax.
mmpur_message 'E' < message class>
<message no>
< parameter 1>'
< parameter 2>
< parameter 3>
< parameter 4>.
Hope it helps you.
05-13-2014 2:12 PM
Hi Senthil,
Can you try like this -
MESSAGE s398(00) WITH ' User is not authorized to Release Purchase Order'
DISLPLAY LIKE 'E'.
Cheers,
Varun Sahu
05-13-2014 2:16 PM
Hi Senthil,
After message use LEAVE LIST-PROCESSING or you can also try LEAVE TO CURRENT TRANSACTION. I am sure it will work.
For example:
IF lv_ernam = sy-uname.
MESSAGE e398(00) WITH ' User is not authorized to Release Purchase Order' .
mmpur_message_forced 'E' 'ME' '118'
LEAVE LIST-PROCESSING.
ENDIF.
Regards,
Jyoti Singh
05-13-2014 2:33 PM
Hi Jyoti,
Isn't LEAVE LIST-PROCESSING statement used in executable programs i.e., for list display! I don't want you think I'm being rude for asking this but have you seen has the statement having any effect on BAdi's?
Cheers,
Varun Sahu
05-13-2014 2:47 PM
Three corrections to apply to your code
Regards,
Raymond
05-13-2014 2:48 PM
Hi Senthil,
don't make validations in POST method, you have CHECK method available for it.
you can present your message and you can set the error flag like this:
IF lv_ernam = sy-uname.
ch_failed = abap_true.
MESSAGE e398(00) WITH ' User is not authorized to Release Purchase Order' .
ENDIF.
You also have parameters:
IM_HOLD
IM_PARK
that allow you to know if user is posting document or not.
that's it, don't use macro mmpur_message_forced!
regards,
Edgar Soares
05-14-2014 7:38 AM
Dear all,
As you said i have implemented in check method, but still the message is not showing or not working.
METHOD if_ex_me_process_po_cust~check.
BREAK SENTHIL.
* S PO Creator should not release the PO - Senthil 05/14/2014
DATA : lt_hdr TYPE mepoheader.
IF sy-tcode = 'ME29N'.
CALL METHOD im_header->get_data
RECEIVING
re_data = lt_hdr.
IF lt_hdr-ernam = sy-uname.
MESSAGE e398(00) WITH 'User is not authorized to Release Purchase Order' .
ENDIF.
ENDIF.
* PO Creator should not release the PO - Senthil 05/14/2014
ENDMETHOD
.
Thanks
Senthil
05-14-2014 8:02 AM
"Never use the ABAP statement MESSAGE in the BAdI ME_PROCESS_PO_CUST. Please use the macro mmpur_message_forced only. This macro only writes a message in the message collector.
If you wish to mark the business object as invalid in order to prevent posting, you must additionally use the INVALIDATE ( ) method of the relevant interface. In this connection, see also the code example in the PROCESS_ITEM method of the BAdI ME_PROCESS_PO_CUST."
cheers
Janis
Is the documentation wrong or outdated?
05-14-2014 9:22 AM
Hi Jānis B,
This code is based on a long working production system code but you are right, mmpur_message_forced should always be used.
The code works because it's inside method check where message collector will catch it and invalidate() is assured by ch_failed attribute.
Anyway I don't know exactly why we have it like this and since is not best practices I'll correct my post.
thanks,
Edgar
05-14-2014 10:19 AM
Hi all,
This works.
DATA: l_released TYPE mmpur_bool,
ls_data TYPE mepoheader,
lr_header TYPE REF TO cl_po_header_handle_mm.
IF sy-tcode = 'ME29N'.
lr_header ?= im_header.
CALL METHOD lr_header->if_release_state_mm~is_released
RECEIVING
re_released = l_released.
IF l_released IS INITIAL.
CALL METHOD lr_header->get_data
IMPORTING
ex_data = ls_data
EXCEPTIONS
failure = 1
OTHERS = 2.
IF sy-subrc = 0.
IF sy-uname NE ls_data-ernam.
ch_failed = abap_true.
mmpur_message_forced 'E' 'ME' '118' '' '' '' ''.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
05-14-2014 8:31 AM
Dear Senthil,
Use 'Message id 'ZMSGS' type 'E' number 'I999' with 'Invalid Order No'.' and here ZMSGS is the message class where you define the 999 or any number message text.
I thiink we cannot use Message Id in Post method, you can use Check method, where you can use
mmpur_message_forced 'E' 'ME' '303' text-002 'Enter Account Assingment category = I' '' ''. to display your message as in grid.
Many Thanks / Himanshu Gupta
05-14-2014 9:03 AM
If you see my last code - its written in check method only. I tried with various messages / with ID - but messages doesn't get popped up.
05-14-2014 9:49 AM
Dear Senthil,
Then you can use mmpur_message_forced and also include the
include mm_messages_mac in your check method.
like...
METHOD if_ex_me_process_po_cust~check.
include mm_messages_mac.
BREAK SENTHIL.
* S PO Creator should not release the PO - Senthil 05/14/2014
DATA : lt_hdr TYPE mepoheader.
IF sy-tcode = 'ME29N'.
CALL METHOD im_header->get_data
RECEIVING
re_data = lt_hdr.
IF lt_hdr-ernam = sy-uname.
mmpur_message_forced 'E' 'ME' '303' text-002 'User is not authorized to Release Purchase Order' '' ''.
ENDIF.
ENDIF.
* PO Creator should not release the PO - Senthil 05/14/2014
ENDMETHOD
Many Thanks/ Himanshu Gupta
05-14-2014 9:58 AM
Thanks Himanshu, this works in Check - the message pops up.
But, if i release and save - the PO gets released without any error message.
I have added the same code in POST as well...but no luck.
05-14-2014 10:14 AM
Whenever you save it first calls the check method then post method, so, after showing message in check method do also CH_FAILED = 'X'.
Many Thanks / Himanshu Gupta
05-14-2014 10:34 AM
Himanshu,
that makes sense and i tried it ...but doesn't work...the flow goes to the message....but message is not hitting on the screen...
instead there comes some other message saying
PO header data still faulty
Message no. MEPO002
05-14-2014 11:22 AM
Attach the screen shot of error message...
Many Thanks/ HImanshu Gutpa
05-14-2014 11:33 AM
Just wanted to make sure. Do we need to have the code in POST as well ?
On Release - Error
05-14-2014 11:36 AM
No you dont have to write the same code again in POST. Method CHECK gets executed automatically before METHOD POST when POST button is clicked.
05-14-2014 1:51 PM
that's the normal message in relase to indicate there is an error. if you hit the "Display messages" button you'll see your message in the message log.
05-15-2014 7:03 AM
05-15-2014 9:15 AM
But if we comment the code inside the enhancment Check method - and release the PO - its getting released without the error message.
But it works as per Edgar Soares response. Need to check with business if they are fine wiht this.
05-15-2014 9:57 AM