Entering content frameRunning Programs Created Dynamically Locate the document in its SAP Library structure

After creating programs dynamically, you can start them in the normal way from the R/3 System. However, you may want not only to create, but also to start programs at runtime. In this case, you can

To start the created or modified program directly from your running program, use:

Syntax

SUBMIT <prog>.

For more information about the SUBMIT statement, see Calling Executable Programs (Reports)

Example

Assume the following simple report:

REPORT ZDYN3.

WRITE / 'Dynamic Program!'.

The following executable program (report) starts, modifies, and restarts ZDYN3:

REPORT ZMASTER1.

DATA CODE(72) OCCURS 10.

DATA LIN TYPE I.

READ REPORT 'ZDYN3' INTO CODE.

SUBMIT ZDYN3 AND RETURN.

DESCRIBE TABLE CODE LINES LIN.

MODIFY CODE INDEX LIN FROM
'WRITE / ''Dynamic Program Changed!''.'.

INSERT REPORT 'ZDYN3' FROM CODE.

SUBMIT ZDYN3.

The output of this program is displayed on two subsequent output screens. The first screen displays:

Dynamic Program!

The second screen displays:

Dynamic Program Changed !

When you use the SUBMIT statement, all modifications made to a program during runtime take immediate effect before they are submitted. In the above example, ZDYN3 is submitted from ZMASTER1 first in its original and then in its modified form, generating different results.

This is not the case if you change the codes of include programs or subroutines dynamically.

Example

Assume the following include program:

*** INCLUDE ZINCLUD1.

WRITE / 'Original INCLUDE program!'.

and an executable program (report) for modifying and including it:

REPORT ZMASTER2.

DATA CODE(72) OCCURS 10.

DATA LIN TYPE I.

READ REPORT 'ZINCLUD1' INTO CODE.

DESCRIBE TABLE CODE LINES LIN.

MODIFY CODE INDEX LIN FROM

            'WRITE / ''Changed INCLUDE program!''.'.

INSERT REPORT 'ZINCLUD1' FROM CODE.

INCLUDE ZINCLUD1.

If you run ZMASTER2, the source code of include program ZINCLUD1 is changed and replaced in the system. However, the last line of ZMASTER2 executes the older version since the runtime object of ZMASTER2 is generated before ZINCLUD1 is modified. Only when ZMASTER2 is run a second time, does the system determine that ZINCLUD1 has been changed. Exactly the same is true if you dynamically modify the source code of a subroutine and call it from within the same program.

One way to solve this problem is to use the INCLUDE statement within an external subroutine that is called by the program. This allows you to create or modify include programs or subroutines and use the updated versions directly in the same program.

Example

Assume the following include program:

*** INCLUDE ZINCLUD1.

WRITE / 'Original INCLUDE program!'.

and an external subroutine:

PROGRAM ZFORM1.

FORM SUB1.
     INCLUDE ZINCLUD1.
ENDFORM.

The following program reads the include program, modifies it, enters it back into the system, and calls the subroutine.

REPORT ZMASTER3.

DATA CODE(72) OCCURS 10.

READ REPORT 'ZINCLUD1' INTO CODE.

APPEND 'WRITE / ''Extension of INCLUDE program!''.' TO CODE.

INSERT REPORT 'ZINCLUD1' FROM CODE.

PERFORM SUB1(ZFORM1).

This produces the following output:

Original INCLUDE program!

Extension of INCLUDE program!

In this case, the updated version of the include program is used in the subroutine because its time stamp is checked when the subroutine is called, and not when the calling program is generated.

 

 

 

 

Leaving content frame