Chapter 2. Dynamic Programming

In this chapter, we will cover recipes related to dynamic programming. This chapter is designed to provide useful recipes related to field symbols and data references, as well as dynamic SQL and ABAP code generation. In this chapter, we will look at the ways of:

  • Using field symbols and data references to print database table contents
  • Applying dynamic Open SQL
  • Dynamic program generation

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.168.203