"
Supported by

Stop the functions module’s error messages

There are standard functions that trigger messages where they shouldn’t. And they shouldn’t because we want to use these functions in non-interactive programs and then, instead of returning the error, an error message is triggered and ruins the whole process.
 
However, being aware of this problem, SAP has provided a quite elegant (but not well documented) way of solving this problem.
 

Imagine that you have the following function module:
 


FUNCTION zzt_message.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  EXCEPTIONS
*"      HELLO
*"      GOODBYE
*"----------------------------------------------------------------------

  MESSAGE e002(00).

ENDFUNCTION.

 
Now, use your imagination and consider the possibility of having this program:
 


REPORT zverso_nao.

CALL FUNCTION 'ZZT_MESSAGE'
  EXCEPTIONS
    hello         = 1
    goodbye       = 2
    OTHERS        = 3.
WRITE 'Por muito tempo achei que a ausência é falta'.

 
What happens is that instead of returning a poem of Carlos Drummond de Andrade, the program will throw an error and stop.
 
But with a simple trick you can give poetry a go:
 


REPORT zverso_sim.

CALL FUNCTION 'ZZT_MESSAGE'
  EXCEPTIONS
    hello         = 1
    goodbye       = 2
    ERROR_MESSAGE = 3
    OTHERS        = 4.
WRITE 'For a long time I have thought that the absence is a fault'.

 
Precisely. Simply add the virtual exception ERROR_MESSAGE before OTHERS and the message will not pop up. SY-SUBRC assumes 3 to warn that there was an error message and the program can bring some beauty to the world.
 
Thank you, Miguel Jorge for the hint.
 
Best greetings from Abapinho.

Um comentário a “Stop the functions module’s error messages”

  1. Kerem Kayacan Diz:

    Hi Abapinho, I have mentioned about this trick in my blog a couple of days ago. RV_INVOICE_CREATE is a good example of this one. You are welcome to stop by and leave a comment: abappolice.co.nf/2015/03/error_message-predefined-exception-for-function-modules-and-methods/

Deixe um comentário


About Abapinho
Abapinho runs on WordPress
Articles (RSS) e Comments (RSS).