Declaring Data as Common Part

To declare data objects as common part, use the DATA statement as follows:

Syntax

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

<data declaration>,
..............
END OF COMMON PART [<name>].

In <data declaration>, you declare all data objects to be included in the common part as explained in The DATA Statement.

Table work areas that are defined with the TABLES statement are automatically shared by subroutines and calling programs.

To use common parts in calling programs and external subroutines, you have to use exactly the same declarations in all programs that are involved. Therefore, you should place the declaration of common parts in INCLUDE programs (see Include Programs).

You can use several common parts in one program. In this case, you must assign a name <name> to each common part. If you use only one common part per program, the name <name> is optional.

To avoid conflicts between programs that have different common part declarations, you should always assign unique names to common parts.

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.

Assume a 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.

Assume a calling program SAPMZTST includes INCOMMON and calls the subroutine ADDIT from the program FORMPOOL.

PROGRAM SAPMZTST.

INCLUDE INCOMMON.

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

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

After starting SAPMZTST, the output appears as follows:

Sum of 2 and 4 is 6

Sum of 7 and 11 is 18

This example has the same function as the example in Calling Internal Subroutines. In the present example, the data objects used in the programs must be declared as common parts because the subroutines ADDIT and OUT are called externally.