Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarative statemnts →  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 differentiate the DATA from the TYPES syntax.


Note

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

Addition 1

... VALUE val|{IS INITIAL}

Effect

You can use the VALUE addition 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 VALUE addition is not allowed in the declaration part of an interface for the DATA statement.

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. 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 VALUE addition, 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 VALUE addition 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 you specify numbers with decimal places or if, in the scientific notation with mantissa, you have an exponent as a start value for data objects of the data types p or f, you must remember that 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.

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 read 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 READ-ONLY addition is always recommended if you want attributes to be invisible, but do not want to execute a GET method for every read access.