The CONSTANTS Statement

If you use a constant frequently in a program, you can declare it as a fixed value variable with the CONSTANTS statement as follows:

Syntax

CONSTANTS <c>[<length>] <type> <value> [<decimals>].

To define structures as constants, write:

CONSTANTS: BEGIN OF <fstring>,
<component declaration>,
..............
           END OF <fstring>.

The parameters of these statements are identical to those for the DATA statement, described in The Basic Form of the DATA Statement and The DATA Statement for Structures.

The use of the <value> parameter is obligatory for the CONSTANTS statement and not optional as in the DATA statement. The start value specified with the <value> parameter cannot be changed during the execution of the program.

CONSTANTS: MYNAME(10) VALUE 'Fred',
BIRTHDAY TYPE D VALUE '19600110',
ZERO TYPE I VALUE IS INITIAL.

The last line of this example demonstrates the purpose of the argument IS INITIAL. Since the parameter VALUE is mandatory for the CONSTANTS statement, you can use IS INITIAL to assign the type specific initial value to a constant.

CONSTANTS: BEGIN OF MYADDRESS,
NAME(20) TYPE C VALUE 'Fred Flintstone',
STREET(20) TYPE C VALUE 'Cave Avenue',
NUMBER TYPE P VALUE 11,
POSTCODE(5) TYPE N VALUE 98765,
CITY(20) TYPE C VALUE 'Bedrock',
END OF MYADDRESS.

This example defines a constant field string MYADDRESS. The components can be addressed by MYADDRESS-NAME, MYADDRESS-STREET, and so on, but they cannot be changed.