Example of User-Defined Elementary Data Types and Objects

The following program is an example of how to declare data objects with user-defined elementary data types.

PROGRAM SAPMZTST.

TYPES MYTEXT(10) TYPE C.
TYPES MYAMOUNT TYPE P DECIMALS 2.

DATA TEXT TYPE MYTEXT.
DATA AMOUNT TYPE MYAMOUNT.

TEXT = ' 4 / 3 = '.
AMOUNT = 4 / 3.

WRITE: TEXT, AMOUNT.

This program produces the following output on the screen:

4 / 3 =                1.33

In this example, user-defined data types MYTEXT and MYAMOUNT are defined with the TYPES statement with reference to elementary data types that are predefined in the system. Then, the data objects TEXT and AMOUNT are declared with the DATA statement. Their data types are determined to be MYTEXT and MYAMOUNT. Values are assigned to the data objects and the contents of the data objects are displayed on the screen.