Introduction

This chapter explores recipes related to dynamic programming. Dynamic programming is a very vast topic. It may be simply defined as a technique whose behavior/effect is only evident at execution time. There are many facets of dynamic programming with ABAP. These include generic programming such as dynamic source code generation. Also specifying parts of the Open SQL statements (clauses) dynamically using string variables, and the creation of data objects based on a type known only at runtime are within the dynamic programming landscape. When using dynamic programming, we may also sometimes need to determine the data type of data objects at runtime. This is called Runtime Type Identification (RTTI).

The ABAP language provides a number of features/options for making programs dynamic or to avoid hardcoding of values. We will start with application of field symbols and references. As an example, we will create a program that will take as input the name of a table and print its contents.

Also we will look at some of the ways in which dynamic SQL may be applied to fulfill simple requirements. We will also cover the option of generating ABAP programs at runtime using the INSERT REPORT statement.

The examples are kept simple in order to emphasize on the dynamic programming concept. We assume that the reader is familiar with basics of SELECT statement, the CREATE DATA statement and the concept of field symbols, and the ASSIGN statement. Also, the knowledge of the cl_abap_datadescr classes is assumed. Moreover, the knowledge of downcasting (widening cast) is also important.