Example: Class based exceptions

With class /NEPTUNE/CL_DR_LIB_SRC_PROG_X we have a REST API which will allow you to execute any executable ABAP Program in your system via the POST /execute endpoint represented via the /NEPTUNE/IF_DR_SRC_PROG_X_POST~EXECUTE interface method.

There is also an optional Importing Parameter available called "VARIANT" with whom you can choose to execute the ABAP Program with a specific Selection Screen Variant which is stored in the System for this program.

What’s the exception scenario here?

Of course when you pass a wrong VARIANT name then this won’t work.

Example

Let’s use an Exception Class to inform the outside that this is the root cause. So we need to define an exception class and create a nice Exception ID with the corresponding exception text.

exceptionHandling Example Class GUI

Then we add this Exception class into the method signature to /NEPTUNE/IF_DR_SRC_PROG_X_POST~EXECUTE.

exceptionHandling Example ClassExecute GUI

By doing this Swagger UI will reflect it immediately:

In addition to the HTTP 200 Response Description you will also get a new HTTP 500 Response body description (Example below related to Open API 3.0):

exceptionHandling Example Class Response

In the "Examples" Dropdown List (Open API 3.0) you will see all possible exceptions which might occur and how their response body Payload will look like.

exceptionHandling Example Class OpenAPI

How will this now look like when a faulty POST /execute request is performed? Let’s simply try this with Swagger UI!

exceptionHandling Example Class Faulty

So a Client who performed this HTTP POST request will get all the necessary information about the problem and can react super precisely to the problem that occurred.

By the way: How could this look like in ABAP?

When you don’t want to catch it you get of course a DUMP which can be reviewed with ST22.

exceptionHandling Example Class ABAP
exceptionHandling Example Class ABAP Error
exceptionHandling Example Class ErrorGUI

If you catch it and want to handle it, this could look something like this (below example also highlights the many ways to handle class based exceptions in ABAP):

exceptionHandling Example Class ABAPHandling
exceptionHandling Example Class ABAPMessage