Entering content frame

Global Data from the Framework Program Locate the document in its SAP Library structure

Subroutines can access all of the global data in the program in which they are defined (main program). You therefore do not need to define a parameter interface if you do not want to change any data in the subroutine, or if very little data is involved.


FORM header.

   WRITE: / 'Program started by', sy‑uname,
          / 'on host', sy‑host,
            'date:', sy‑datum, 'time:', sy‑uzeit.



This example creates a subroutine called header, which, like the example of an include program, displays a list header.

However, if you want subroutines to perform complex operations on data without affecting the global data in the program, you should define a parameter interface through which you can pass exactly the data you need. In the interests of good programming style and encapsulation, you should always use a parameter interface, at least when the subroutine changes data.

Protecting Global Data Objects Against Changes

To prevent the value of a global data object from being changed inside a subroutine, use the following statement:


This statement may only occur between the FORM and ENDFORMstatements. With LOCAL, you can preserve the values of global data objects which cannot be hidden by a data declaration inside the subroutine.

For example, you cannot declare a table work area that is defined by the TABLES statement with another TABLESstatement inside a subroutine. If you want to use the table work area locally, but preserve its contents outside the subroutine, you must use the LOCALstatement.


REPORT demo_mod_tech_local.

TABLES sflight.

PERFORM tabtest1.
WRITE: / sflight-planetype, sflight-price currency sflight-currency.

PERFORM tabtest2.
WRITE: / sflight-planetype, sflight-price currency sflight-currency.

FORM tabtest1.
  sflight-planetype = 'A310'.
  sflight-price = '150.00'.
  WRITE: / sflight-planetype, sflight-price currency sflight-currency.

FORM tabtest2.
  LOCAL sflight.
  sflight-planetype = 'B747'.
  sflight-price = '500.00'.
  WRITE: / sflight-planetype, sflight-price currency sflight-currency.

When you run the program, the following is displayed:

A310                150.00

A310                150.00

B747                500.00

A310                150.00

In this example, the program creates a table work area sflight for the database table sflight. Different values are assigned to the table work area sflight in tabtest1 and tabtest2. While the values assigned in tabtest1 are valid globally, the values assigned in tabtest2 are only valid locally.



Leaving content frame