Entering content frame

Shared Data Areas Locate the document in its SAP Library structure

CautionThe following statements are obsolete and are only available to ensure compatibility with Releases prior to 4.6 and 6.10. The statements may appear in older programs but should no longer be used.

 

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 TABLESand 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 DATA 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 area 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 shared data areas in one program. In this case, you must assign a name nameto each. If you only have one common area in each program, you do not have to specify a name. To avoid conflicts between programs that have different common area declarations, you should always assign unique names to common areas.

Example

Assume an include program incommon contains the declaration of a shared area 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.

Assume a program form_test that 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.

form_test 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 TABLESstatement. In the subroutine tabtest2, the global work area is protected against changes in the subroutine by the LOCALstatement.

 

 

Leaving content frame