CONSTANTS

Short Reference

Syntax

CONSTANTS const [options].

Effect

This statement declares a constant data object - that is, a constant const. The content of a constant cannot be changed at runtime of an ABAP program. You can only use it as an operands in read positions of ABAP statements. Constants that you declare in the declaration section of a class or an interface belong to static attributes of that class/interface.
The name conventions apply to the name const. The syntax of the additions options of the CONSTANTS statement, for declaring constants, corresponds to that of the DATA statement for declaring variables. The only differences are that the READ-ONLY addition is not possible and within the declaration of a structure, the INCLUDE statement cannot be used.

In contrast to the DATA statement, you have to specify an Startwert with the addition VALUE using the CONSTANTS statement. The same restrictions as for the DATA statement apply. This has the following implications for the declaration of constants:

Note

If you use the class component selector, you can also use the interface name to access static attributes of interfaces that were declared using CONSTANTS.

Example

The statements below declare a numeric constant, a constant structure and a constant reference. You can use the reference, for example, in comparisons, or pass it on to procedures.

CONSTANTS pi TYPE p LENGTH 8 DECIMALS 14
                 VALUE '3.14159265358979'.

CONSTANTS: BEGIN OF sap_ag,
             zip_code TYPE n LENGTH 5 VALUE '69189',
             city     TYPE string VALUE `Walldorf`,
             country  TYPE string VALUE `Germany`,
           END OF sap_ag.

CONSTANTS null_pointer TYPE REF TO object VALUE IS INITIAL.