GUIDELINE 6.46
Using Dynamic Programming Techniques
ABAP_BACKGROUND
The use of dynamic programming techniques includes the following:
Accessing dynamic memory objects, that is, dynamic data objects (strings
and internal tables), as well as instances of classes and anonymous data
objects
Dynamically accessing data objects using reference variables and field
symbols (to a certain extent, this also includes accessing generically
typed formal parameters in procedures)
Dynamically invoking procedures or entire programs
Generically generating data types and using them to create anonymous
data objects
Generically developing programs in which parts of the statements are
specified using dynamic tokens, or entire programs are only generated at
runtime
In this sense, handling reference variables can also be considered a
dynamic technique. The dynamic type (the object to which the reference
refers) can be more specific than the static type of the variable, which
entails polymorphic behavior and becomes apparent during assignments in
the form upcasts or
downcasts .
ABAP_RULE
Use dynamic programming techniques with care
Use dynamic programming techniques only when this is necessary and
reasonable. Use only as many dynamic language elements as required to
carry out the assigned task.
ABAP_DETAILS
The advantage of dynamic programming techniques is an increased
flexibility when creating programs. Dynamic programming techniques e
nable flexible and generic services to be developed that meet various
requirements. The price to be paid for this advantage is that dynamic
programming techniques may decrease the static checkability, legibility,
maintainability, testability, performance, and also
security .
Security standards may even prohibit the use of high-risk dynamic
programming techniques.
This section describes various dynamic programming techniques. These
range from using strings , which we explicitly
recommend, and using internal tables , which form
a basis of ABAP programming, to generating
entire programs , which we advise against. The higher the dynamics,
the more comprehensive the precautionary measures to be taken when using
these techniques. Already the simple access to data objects involves a
corresponding partial aspect, which was addressed in the rule for
Runtime Errors when Accessing Data
Objects . The rules in this section extend such specific rules and
provide a more general framework.
Always consider the following aspects when deploying dynamic techniques:
Programs that work with dynamic techniques are usually more complex and
harder to understand than programs that use only static techniques. This
has a negative effect on maintainability.
In dynamic programming, many checks that are otherwise performed during
compilation can be performed only at runtime. This considerably
increases the risk of exceptions or runtime errors.
Checking the dynamic parts at runtime can reduce the processing speed,
as the checks must be repeated each time the parts are used again.
More tests are required, since numerous states of a dynamic program and
possible error situations must be checked.
The significance of these aspects differs for the various dynamic
programming techniques. For example, a program that uses strings is by
no means more complex than a program that works only with text fields.
In such a case, a range of details must nevertheless be taken into
account.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved