Entering content frameShared Data Areas Locate the document in its SAP Library structure

For the sake of completeness, this section describes a technique that allows you to access the global data of the calling program from an external subroutine. To do this, you declare a common data area for the calling program and the program containing the subroutine. All interface work areas declared using TABLES and NODES behave like the common data area.

Like external subroutines themselves, you should use common data areas very sparingly. The rules for accessing common data areas can become very complicated if you call function modules from nested subroutines.

You declare a common data area in all programs concerned using the statement:

DATA: BEGIN OF COMMON PART [<name>],

        
      END OF COMMON PART [<name>].

Between the two DATA statements, you declare all of the data you want to include in the common data area.

The common part declaration must be exactly the same in all of the programs in which you want to use it. It is therefore a good idea to put the declaration in an include program.

You can use several common parts in one program. In this case, you must assign a name <name> to each common part. If you only have one common part in each program, you do not have to specify a name. To avoid conflicts between programs that have different common part declarations, you should always assign unique names to common parts.

Example

Assume an include program INCOMMON contains the declaration of a common part NUMBERS. The common part comprises three numeric fields: NUM1, NUM2, and SUM:

***INCLUDE INCOMMON.

DATA: BEGIN OF COMMON PART NUMBERS,
        NUM1 TYPE I,
        NUM2 TYPE I,
        SUM  TYPE I,
      END OF COMMON PART NUMBERS.

The program FORMPOOL includes INCOMMON and contains the subroutines ADDIT and OUT:

PROGRAM FORMPOOL.

INCLUDE INCOMMON.

FORM ADDIT.
  SUM = NUM1 + NUM2.
  PERFORM OUT.
ENDFORM.

FORM OUT.
  WRITE: / 'Sum of', NUM1, 'and', NUM2, 'is', SUM.
ENDFORM.

A calling program FORM_TEST includes INCOMMON and calls the subroutine ADDIT from the program FORMPOOL.

PROGRAM FORM_TEST.

INCLUDE INCOMMON.

NUM1 = 2. NUM2 = 4.
PERFORM ADDIT(FORMPOOL).

NUM1 = 7. NUM2 = 11.
PERFORM ADDIT(FORMPOOL).

This produces the following output:

Sum of 2 and 4 is 6

Sum of 7 and 11 is 18

The subroutines in the program FORMPOOL access the global data of the shared data area.

Example

Assume a program FORMPOOL that contains two subroutines TABTEST1 and TABTEST2 as follows:

PROGRAM FORMPOOL.

TABLES SFLIGHT.

FORM TABTEST1.
  SFLIGHT-PLANETYPE = 'A310'.
  SFLIGHT-PRICE = '150.00'.
  WRITE: / SFLIGHT-PLANETYPE, SFLIGHT-PRICE.
ENDFORM.

FORM TABTEST2.
  LOCAL SFLIGHT.
  SFLIGHT-PLANETYPE = 'B747'.
  SFLIGHT-PRICE = '500.00'.
  WRITE: / SFLIGHT-PLANETYPE, SFLIGHT-PRICE.
ENDFORM.

A program FORM_TEST calls TABTEST1 and TABTEST2 as follows:

PROGRAM FORM_TEST.

TABLES SFLIGHT.

PERFORM TABTEST1(FORMPOOL).
WRITE: / SFLIGHT-PLANETYPE, SFLIGHT-PRICE.

PERFORM TABTEST2(FORMPOOL).
WRITE: / SFLIGHT-PLANETYPE, SFLIGHT-PRICE.

SAPMZTST then produces the following output:

A310 150.00

A310 150.00

B747 500.00

A310 150.00

All of the programs can access the table work area SFLIGHT, declared with the TABLES statement. In the subroutine TABTEST2, the global work area is protected against changes in the subroutine by the LOCAL statement.

 

 

 

Leaving content frame