Skip to main content

SAP: Best practice for SAP message output in non-SAP-GUI contexts

Submitted by Stefan Barsuhn on

Imagine you see an error message in WebUI or in some other interface. You manage to identify the message class and number, go to SE91, do a Where-used and find - nothing. The reason is that either Where-used was not updated correctly or (most likely) somebody did not both to use the message command to output the message but just hardcoded the message ID, number and type.

Sound familiar? At least for me it is something that I see more often than I'd like to. So I would like to emphasize that the SAP best practice for issuing messages to the user is to always, always, always use the message command, no exceptions.

This is especially true outside of SAP GUI dialogs (e.g. interfaces or WebUI) where you pass all your messages to some sort of message handler. 

So whenever you need to return a message to the customer via handler method lr_handler->add_message, e.g. error message of class zexample, message number 001 and variables lv_1, lv_2 and lv_3, always follow the following template (please) - your fellow developers will thank you for it!

" FIRST the message statement (please add it via Pattern, so the actual error text can be seen)
* An error in example & occured while processing class & method &
message  e001(zexample) with lv_1 lv_2 lv_3 into data(lv_string).

" THEN call your handler class and use the sy fields
call method lr_handler->add_message
   exporting
      type   = sy-msgty
      number = sy-msgno
      id     = sy-msgid
      v1     = sy-msgv1
      v2     = sy-msgv2
      v3     = sy-msgv3.

Notes:

  • Using the sy fields allows you to conveniently reuse the handler method coding (you could even put it into a separate method or structure your coding that you only need to call it once)
  • Sometimes even the SAP Standard will take care of passing the sy message values to the message handler - so check your calling functions/methods! 

Update 2020-09-17: Just found out that, in CRM WebUI, you can also see the message ID (unless it's not displayed anyway) by adding parameter BSPWD_USER_LEVEL  to your user profile (SU3) and set a value of 5. Afterwards, hover over the message text and a tooltip will display the message ID etc.

 

Tags