Application Development 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: 

Error message in BaDi

Former Member
0 Kudos


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

27 REPLIES 27

Former Member
0 Kudos

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

0 Kudos

No Prasenjit - this also not working.

0 Kudos

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

0 Kudos

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

atul_mohanty
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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

raymond_giuseppi
Active Contributor
0 Kudos

Three corrections to apply to your code

  • Use macro mmpur_message_forced (as

Former Member
0 Kudos

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

0 Kudos

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

0 Kudos

Read the documentation of BADI, please, and read all of it - I'm only copy-pasting part of it here:


"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

Edit in:

Is the documentation wrong or outdated?

0 Kudos

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

0 Kudos

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.

himanshu_gupta13
Employee
Employee
0 Kudos

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

0 Kudos

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.


0 Kudos

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



0 Kudos

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.

0 Kudos

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

0 Kudos

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

0 Kudos

Attach the screen shot of error message...

Many Thanks/ HImanshu Gutpa

0 Kudos

Just wanted to make sure. Do we need to have the code in POST as well ?

On Release - Error

0 Kudos

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.

0 Kudos

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.

0 Kudos

I think this is an another error related to PO Header and this error is coming in way execution before the customize error implemented in BAPI comes. Hence, it halts the program before,

Ref. to discussion

Many Thanks / Himanshu Gupta

0 Kudos

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.


gaurab_banerji
Active Participant
0 Kudos

This message was moderated.