No matter how many times mentioned before (thanks to Rahul GopinathAmit BeheraSrinivas Dummu and Mike), I still see sy-subrc check after a function module call without exceptions.

This is so wrong. According to ABAP keyword documentation:

If no exception is raised, a call sets sy-subrc to 0.

So in the above example, sy-subrc will always be equal to zero and condition will never be satisfied. This applies to method calls, too. Let’s experiment to make sure. Here is a test program…

 …and the result:

This test confirms ABAP keyword documentation but leaves us with a question: How do we handle errors of a function module without any exception? Let’s dive into the code of  RV_INVOICE_CREATE , function module in our bad example.

It seems that the function module throws dialog messages. So if an error message is raised, the program run will stop with a message. That is okay until we need batch processing. If we need to create invoices in batch and we would like to continue processing despite an error in one of calls, our hands are not tied. SAP provides us with a hidden feature: predefined exception  ERROR_MESSAGE . We can fix our first example with a simple move:

This exception will catch all  E and  A type messages and mesage details can be accessed in SY structure. See ABAP keyword documentation for more details.

Leave a Reply