SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP Programming Guidelines → Robust ABAP → Dynamic Programming Techniques →Runtime Errors in Dynamic Processing
Background
When dynamic techniques are used, various exception situations can arise that can never occur when the corresponding static techniques are used because they can be checked statically.
Rule
Preventing Runtime Errors in Dynamic Processing
Respond appropriately to all possible error situations when using dynamic techniques.
Details
The different dynamic techniques also require different reactions to the possible exception situations. Examples:
These examples illustrate how the use of dynamic techniques can lead to more complex and less clear code due to the numerous possible exception situations. Of course, the more the mentioned techniques are combined, the more complex and less clear the code becomes. Therefore, dynamic programming techniques must always be used with care.
Note
If it is not possible to particular error situations, for example, because no exception that can be handled exists, it must be ensured that this error situation never occurs and this then verified in extensive test scenarios.
Bad example
The seemingly legible source code section uses almost only dynamic operands and tokens. Neither the ABAP Compiler nor the reader can know the content of the specified variables at runtime. An error in one of these variables results in a termination of the program.
Good example
The following source code corrects the above example with an appropriate error handling — this reduces the legibility, of course. Here, it is additionally considered that an initial dynamic WHERE condition means that no restrictions are imposed. As shown here, this case must be explicitly avoided. Otherwise, the entire table content will be deleted.