Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarative statemnts →  Data Types and Data Objects →  Declaring Data Objects 

CONSTANTS

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CONSTANTS const [options]. 

Effect

This statement declares a constant data object, const for short. The content of a constant cannot be changed at runtime of an ABAP program. You can only use it as an operand 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 or interface.

The naming conventions apply to the name const. The syntax of the additions options of the statement CONSTANTS statement for declaring constants matches the statement DATA for declaring variables. Only the additions READ-ONLY, BOXED, and the declaration of LOB handle structures are not possible. As previously, the statement INCLUDE cannot be used within the declaration of a structure.

Unlike the DATA statement, you must specify an initial value with the addition VALUE when using the CONSTANTS statement. The same restrictions as for the DATA statement apply. This has the following implications for the declaration of constants (with data type deep):

  • You can specify a start value val for the ABAP types string and xstring only.
  • Constant internal tables, reference variables, and structures with not purely character-like flat components can be assigned their initial value by IS INITIAL only, and are therefore always initial.


Notes

  • 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.
  • Constants are stored in the PXA and are available to all programs.

Example

The statements below declare a numeric constant, a constant structure, and a constant reference. You can use the reference in comparisons, for example, or pass it 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.