Entering content frame Creating a New Program Dynamically Locate the document in its SAP Library structure

To create a new dynamic program at runtime of an ABAP program, you must use an internal table. For this purpose, create the internal table with a single column of type character and a row width of 72. You can use any process described under Filling Internal Tables to write the source code of your new program into the internal table. You can use internal fields, whose contents depend on the flow of the program you use to create the new program. The following example shows how you can carry this out:

Example

REPORT demo_special_tech_dyn_insert.
DATA: code TYPE TABLE OF rssource-line.
* type of an editor line: rssource-line

APPEND  'REPORT ZDYN1.'
         TO code.

APPEND  'WRITE / ''Hello, I am dynamically created!''.'
         TO code.

Two lines of a simple program are added to the internal table CODE.

Now you must transfer the new module - in this case, an executable program (report) - into the program library. Use the following statement:

Syntax

INSERT REPORT <prog> FROM <itab>.

If a program with this name does not already exist, it is created with the following attributes:

The new program <prog> is stored persistently on the database but is not assigned to a package. It is therefore not affected by the transport system.

Caution

If a program with the name <prog> already exists, its source code is replaced with a new one from the internal table <itab> without prior warning. All other attributes remain intact. Therefore, you must be very careful when naming dynamically generated programs.

You can explicitly enclose the name of the program <prog> in single inverted commas or specify a character field that contains the name. The program name does not have to correspond with the name in the source code, but it is advisable. <itab> is the internal table that contains the source. Hence, for the above example you can write:

Example

INSERT REPORT 'ZDYN1' FROM code.

or

DATA rep(8) TYPE c.

rep = 'ZDYN1'

INSERT REPORT rep FROM code.

In the ABAP Editor initial screen, you can call and change all components of the new program.

Example

You can call the ABAP Editor for the above example:

This graphic is explained in the accompanying text

 

Note

Instead of INSERT REPORT you can use the GENERATE SUBROUTINE POOL statement, which creates temporary external subroutines in the main memory (see Creating and Starting Temporary Subroutines).

 

 

Leaving content frame