Example of Structures

The following program is an example of how to declare structured data objects as a structure.

PROGRAM SAPMZTST.

TYPES: BEGIN OF NAME,
TITLE(5) TYPE C,
FIRST_NAME(10) TYPE C,
LAST_NAME(10) TYPE C,
END OF NAME.

TYPES: BEGIN OF MYLIST,
CLIENT TYPE NAME,
NUMBER TYPE I,
END OF MYLIST.

DATA LIST TYPE MYLIST.

LIST-CLIENT-TITLE = 'Lord'.
LIST-CLIENT-FIRST_NAME = 'Howard'.
LIST-CLIENT-LAST_NAME = 'Mac Duff'.
LIST-NUMBER = 1.

WRITE LIST-CLIENT-TITLE.
WRITE LIST-CLIENT-FIRST_NAME.
WRITE LIST-CLIENT-LAST_NAME.
WRITE / 'Number'.
WRITE LIST-NUMBER.

This program produces the following output on the screen:

Lord Howard Mac Duff
Number 1

In this example, the structured data types NAME and MYLIST are defined with the TYPES statement. The structure NAME contains three components: TITLE, FIRST_NAME and LAST_NAME, with the predefined elementary data type C. The structure MYLIST contains the two components CLIENT and NUMBER. CLIENT itself is already structured because it is given data type NAME. NUMBER is elementary, and has the predefined data type I. A structured data object is declared using data type MYLIST. Values are assigned to the components and their contents are then displayed on the screen.