A Useful Option for Handling Messages as Exceptions during Function Module Calls (Extremely useful if you are developing RF Programs in ABAP)
When developing Dialogue transactions using ABAP, or while doing updates in standard SAP Enhancements, I have often come across scenario where my program calls a standard Function Module which however does not handle a particular condition and throws Error Messages Internally. This, results in Program behaving indifferently. A typical scenario where you would like to avoid Error Messages would be while developing RF Programs. In this blog I would like to share with you a small option that helped me a lot in my ABAP developments.
Case where the function module throws error internally and the main program cannot handle it.
I am creating a function module Y_THROW_MESSAGE which has a Message Statement as shown below:
I create a program,Y_HANDLE_MSG which calls this function module. You may note that the function module does not throw any exception.
On Execution the program is unable to proceed since the function module throws an Error Message.
However, now we will handle this message like handling any other exception normally thrown by a function moudle.
Now, we have handled the internal message by setting the sy-subrc value through ERROR_MESSAGE option. Thus we can check the sy-surbc and decide the program flow.
I have found this option to be useful when calling standard function modules in custom reports or transactions or inside sap enhancements. You now have control over your transaction. This is extremely useful if you are developing RF Programs in ABAP. So, now if your delivery updates BAPI or a Print Function throws Error internally in the function module you could handle it as an exception and customize the Message in your RF Program.