messages in function calls abort your reports/functions
Foreign function calls can mess with your status or even worse abort the transaction or report. There are a lot of function calls the use MESSAGE to inform/warn the user or use it without the optional RAISING in combination with an Abort or Error message type, which causes your nice transaction to abort. Well there is hope. ABAP knows the special error_messages exception which changes the way MESSAGEs are handled.
Assuming you have the following code
call function 'do_something'
importing
iv_foo = lv_bar
exceptions
not_found = 1
invalid = 2
.
if sy-subrc <> 0.
* handle the error
endif.
if the function call do_something performs a MESSAGE call the following will happen:
- If
typeis one of W,S or I the status bar in the SAP GUI will update with a message which you have no control over. - If
typeis one of A or E and theMESSAGEstatement has noRAISINGoption. The transaction or report will abort with a short dump.
To avoid this all you have to do is add the special exception error_messages to the end of the exception list. This has the nice side effect that when catching the exception the message text and values are available in the sy-msg* just as if the function call used the RAISING option.
call function 'do_something'
importing
iv_foo = lv_bar
exceptions
not_found = 1
invalid = 2
error_messages = 3
.
if sy-subrc = 3.
* the MESSAGE values are now available in the sy-msgno, sy-msgty
* and the other sy-msg* fields available.
elseif sy-subrc <> 0.
* handle the error
endif.
Now the error still persists, but at least you clean up and abort gracefully.
25 March 2009
