SAP ASSERTIONS - Guide
Get Example source ABAP code based on a different SAP table
GUIDELINE 5.16
Assertions
ABAP_BACKGROUND
The
Assertions, together with breakpoints and logpoints, form the checkpoints of a program; these are not part of the application logic, but are used for development and maintenance support.
ABAP_RULE
Use assertions to check the status of a program for consistency at all locations where this is possible.
ABAP_DETAILS
Each program logic is based on certain assumptions. If these assumptions are not met, there are obviously errors in the program and there is no point in executing it any further. In this case, you should stop the execution of the program immediately to avoid any further damage, such as persisted incorrect data. In this way, you can also identify errors early on that would otherwise remain undiscovered.
The
Furthermore, assertions make program maintenance easier by enabling developers to express their assumptions explicitly. The reader of the source text is immediately aware of these assumptions; this gives them a better understanding of the program logic.
If it will take too long to check an
Exception
Do not use assertions to check statuses that are out of the developer's control, such as invalid call parameter values or availability of external resources. In this case, use exceptions, as this enables the caller to react to such unexpected statuses.
Example
The following source text shows a program extract in which a line is read from an internal table. The program logic here assumes that this access is always successful. This expectation is checked at runtime by the subsequent assertion, and also documented for the reader.
READ TABLE items INTO current_item • current_index.
ASSERT sy-subrc = 0.
...