Get Example source ABAP code based on a different SAP table
• VALUE DATA • IS INITIAL DATA • VALUE CLASS-DATA • IS INITIAL CLASS-DATA • VALUE STATICS • IS INITIAL STATICS • VALUE CONSTANTS • IS INITIAL CONSTANTS • READ-ONLY DATA • READ-ONLY CLASS-DATA
DATA>, data_options> Short Reference >
ABAP_SYNTAX ... $[ VALUE val$|${IS INITIAL$} $] $[ READ-ONLY $].>
ABAP Addition 1 ... VALUE val$|${IS INITIAL$}> 2 ... READ-ONLY>
What does it do? The additions VALUE> and READ-ONLY> are specifically for data objects and distinguish the DATA> syntax from the TYPES > syntax.
Latest notes: NON_V5_HINTS As well as the additions VALUE> and READ-ONLY>, the syntax also allows the obsolete addition COMMON PART>>. ABAP_HINT_END
ABAP Addition
What does it do? The addition VALUE> can be used to define a start value> val> for the content of a variable for all forms of the variable declaration. This value is used to initialize the variable when it is created before LOAD-OF-PROGRAM>>. The addition VALUE> is not allowed in the declaration part of an interface for the statement DATA>. The start value val> can either be specified as a literal or as a predefined constant. Constants, rather than using the actual value, work like the literal that is specified after VALUE> when it is declared. A check is usually only performed to check whether the length of the specified value matches the data type and that a syntax check warning occurs if there are any derivations. Only for time stamp type utclong> does a character literal that contains a valid representation> of a time stamp need to be specified. 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 during program generation when the program is activated. If the literal cannot be converted to the data type, no syntax error occurs and exception is raised when the program is generated instead. BEGIN_SECTION SAP_INTERNAL_HINT A ... TYPE x LENGTH 2 VALUE 1234> gives another result then ... TYPE xstring VALUE 1234>! In the latter case 1234> works like '1234'>. This is also different from using ... = 1234> later. END_SECTION SAP_INTERNAL_HINT Without the addition VALUE>, or if IS INITIAL> is specified, the content is initial. The initial values > depend on the data type. The initial values of elementary types are dependent on the built-in ABAP types>. In the case of initial structures, the components are initial, initial reference variables contain the null reference>, which does not point to an object, and initial internal tables do not contain any lines. The addition VALUE> is possible for all data types, particularly 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 non-character-like and flat components.
A start value should be specified according to type. In particular, no values that are longer can 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 specified as a start value for data objects of the data types p> or f> in scientific notation with mantissa and exponents, it should be ensured 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.
If the data object is character-like, the enumerated constants> val1>, val2>, ... of the value set of an enumerated type> enum> can also be specified for val>. The constant then is given the name of the enumerated constant as its value.
The value operator> VALUE>> can also be used to construct the content of complex data objects (structures, internal tables).
In the declaration part> of global classes> the character representation of default values is limited to 132 characters. BEGIN_SECTION VERSION 5 OUT All positions exceeding 132 characters will be truncated when working in the form-based class builder in SE24 >>. END_SECTION VERSION 5 OUT When you work in BEGIN_SECTION VERSION 5 OUT the source code-based view in SE24>> and in END_SECTION VERSION 5 OUT ADT>, exceeding characters will not be truncated. However, a syntax warning appears. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 Declaration of data by specifying the initial value, where one value is specified by a constant. ABEXA 00175 ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 The following example demonstrates that if a constant is used after VALUE>, the literal that is specified after the VALUE > addition is evaluated. The variable text1> is given the full content of the literal while the variable text2> is assigned the value of the constant that contains only the digits of the literal and any leading zeros in accordance with the conversion rule> from c> to n>. ABEXA 00176 ABAP_EXAMPLE_END
ABAP Addition
What does it do? This addition is always possible in the public> visibility section class or in an interface. This addition ensures that an attribute declared using DATA> can be read from outside of the class but can only be changed using methods of the class or its subclasses. This addition has no effect on the friends> of the class. A class attribute defined using READ-ONLY> can be used outside of the class, its friends, and subclasses only in read positions> in ABAP statements.
Latest 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 is not executed for every read for performance reasons. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 Use of the static constructor as the factory method of a class with instances created privately. The reference to the created singleton objects is available in the READ-ONLY> attribute clsref>. ABEXA 00177 ABAP_EXAMPLE_END