Programming

Unhandled Exceptions and Short Dumps in ABAP

Exceptions in ABAP can be handled using the TRY and CATCH statements. However, when an exception goes unhandled, a runtime error occurs and a short dump is created.

 

An example of an unhandled exception occurs if you run the code below and enter “0” for the parameter. As a result, you’ll get an unhandled exception for dividing by zero.

 

SELECTION-SCREEN BEGIN OF BLOCK selection.

   PARAMETERS: p_param TYPE i.

SELECTION-SCREEN END OF BLOCK selection.

START-OF-SELECTION.

DATA: result TYPE i.

 

result = 10 / p_param.

 

WRITE: result.

 

If users are accessing the system using SAP GUI, they’ll see a short dump, like that shown in the figure below. The short dump contains a lot of useful information for a developer, but it’s not very user-friendly and looks like Microsoft’s dreaded Blue Screen of Death.

 

Short Dump in SAP GUI

 

When using a Web Dynpro application, the short dump will be displayed to the user as a 500 SAP Internal Server Error, as shown below. The user will only see the 500 error, but the full short dump will be logged in the backend ABAP system.

 

500 SAP Internal Server Error

 

When using OData web services, the unhandled exception is turned into a 500 error response, as shown in the next figure, which can be handled in any way by the application using the service and will be logged in the backend ABAP system.

 

500 Error Response from OData Service

 

No matter how the user was accessing the system, the short dump is logged and can be viewed by entering Transaction ST22. The selection screen is pictured below, where you can see the Today and Yesterday buttons, which will show all of the unhandled exceptions that occurred on the selected day. The Own Selection section contains various selection options, such as Date and Time, that can be used to search for a specific exception that occurred. Click the Start button to search based on the entered selections. If a user reports that an error occurred, you can use these selections to find the exception, using the username for the user that reported the error and the day on which the user said the error occurred.

 

Transaction ST22 Selection Screen

 

The list of errors will be displayed based on the selections you entered or the day that you selected (see below). Double-click any exception to see more information about that exception.

8

Result List of Unhandled Exceptions Selected from Transaction ST22

 

After opening one of the exceptions, you’ll be taken to a long text view of the exception, which will contain a lot of useful information, as shown below. On the left-hand side is a navigation tree for the various parts of the short dump log.

 

Long Text View of Short Dump

 

The following paragraphs go over a few of the items that are the most important to developers.

 

The top of the screen shows some basic information about the exception that occurred, such as the name of the program in which the exception occurred, the date and time that the exception occurred, and the type of exception. In the example below, you can see that the ABAP program is ZTEST and the exception type is CX_SY_ZERODIVIDE. There also is some additional information in the Short Text section to help you understand what the exception means. 

Basic Information in Short Dump

 

For a developer, the Source Code Extract is usually the most useful element. Source Code Extract The arrows boxed in the figure below show the line of code where the exception occurred; you can see that it occurred when performing a division operation. You can double-click the source code extract to view the code in the source code editor.

 

Short Dump Source Code Extract

 

You can also see the values of the program’s variables at the time the exception occurred in the Chosen variables section. In the next figure, you can see that p_param was not assigned a value, and so it holds the initial value of zero; result was also never given a value, and so it also holds the value of zero.

 

Short Dump Chosen Variables Section

 

Sometimes, these exceptions will occur not in your own code but in SAP-standard ABAP code that may have been called when your program accessed a function module, method, or BAPI written by SAP. In this case, you can find more information or possibly a support note from SAP by entering the program where the exception occurred and the exception type in to the Search option at http://support.sap.com.

 

Editor’s note: This post has been adapted from a section of the book ABAP: An Introduction by Brian O’Neill and Jelena Perfiljeva.

Recommendation

ABAP: An Introduction
ABAP: An Introduction

Step into ABAP with this beginner's guide. First understand ABAP syntax and find out how to add data and logic to your applications. Then delve into backend programming: learn to work with the ABAP data dictionary, create database objects, and process and store data. Round out your skill set by practicing error handling, modularization, string manipulation, and more. With guided examples, step-by-step instructions, and detailed code you'll become an ABAP developer in no time!

Learn More
SAP PRESS
by SAP PRESS

SAP PRESS is the world's leading SAP publisher, with books on ABAP, SAP S/4HANA, SAP IBP, intelligent technologies, SAP Business Technology Platform, and more!

Comments