Skip to content

ABAP Keyword Documentation →  ABAP Programming Guidelines →  Robust ABAP →  Dynamic Programming Techniques 

Using Dynamic Programming Techniques

Other versions: 7.31 | 7.40 | 7.54

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 via 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.

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.

Details

The advantage of dynamic programming techniques is an increased flexibility when creating programs. Dynamic programming techniques enable you to develop flexible and generic services that meet various requirements. The price you have to pay 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 you must take 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.

You should 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, as you must check numerous states of a dynamic program and possible error situations.

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, you must nevertheless take a range of details into account.