Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarations →  Declaration Statements →  Data Types and Data Objects →  Declaring Data Objects →  DATA 

DATA - data_options

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


... [ VALUE val|{IS INITIAL} ] 
    [ READ-ONLY ].

Extras

1. ... VALUE val|{IS INITIAL}
2. ... READ-ONLY

Effect

The additions VALUE and READ-ONLY are specifically for data objects. They distinguish the DATA syntax from the TYPES syntax.


Note

As well as the additions VALUE and READ-ONLY, the syntax also allows the obsolete addition COMMON PART.

Addition 1

... VALUE val|{IS INITIAL}

Effect

The addition VALUE can be used to define (for all forms of the variable declaration) a start value val for the content of the variable. This is used to initialize the variable when created before LOAD-OF-PROGRAM. The addition VALUE is not allowed in the declaration part of an interface in the statement DATA.

The start value val can either be specified as a literal or as a predefined constant. Where constants are involved, rather than their actual values being used, they function like the literal specified after VALUE when the constant is declared. A check is usually performed to verify if the length of the specified value matches the data type. Any deviations result in a warning from the syntax check. If the data type of the literal does not match the data type of the declaration, it is usually converted in accordance with the conversion rules for elementary data types.

Without the addition VALUE, or if IS INITIAL is specified, the content is set to an initial value. The initial values are dependent on the data type.

In the case of initial structures, the components are initial; initial reference variables contain the null reference that does not point to an object, and initial internal tables do not contain any rows.

The addition VALUE is possible for all data types, in particular for the deep types (strings, reference types, table types, or structured types with deep components, including boxed components). A start value val, however, can only be specified for the ABAP types string and xstring. Otherwise, only IS INITIAL is possible. IS INITIAL is also the only possible start value for structures with components that are not purely character-like and flat.

Programming Guideline

Specifying Start Values Appropriate to the Type


Notes

  • A start value should be specified according to type. In particular, no longer values should be specified and, in the case of certain data types such as d and t, the length must match exactly.
  • If numbers with decimal places are specified or if, in the scientific notation with mantissa, an exponent is used as a start value for data objects of the data types p or f, there are no literals for these numbers. Instead, the character literals must be specified with the appropriate content. These are then converted into the numeric data type in accordance with the conversion rules for elementary data types. The same applies to byte-like data objects.
  • The value operator VALUE can also be used to construct the content of complex data objects (structures, internal tables).

Addition 2

... READ-ONLY

Effect

This addition is always possible in the public visibility area of a class or in an interface. This addition makes an attribute declared using DATA readable from outside of the class, but can only be changed using methods of the class or its subclasses. This addition is ignored by the friends of the class.

A class attribute defined using READ-ONLY can be used outside of the class, its friends, and subclasses only at reader positions in ABAP statements.


Notes

  • The declaration of attributes using the addition READ-ONLY does not prevent methods of the class from passing references to these attributes externally as reference variables or field symbols and therefore making the attributes modifiable outside of the class.
  • The addition READ-ONLY is always recommended if attributes need to be invisible, but a GET method for every read access is to be avoided.