Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Declarations →  Declaration Statements →  Data Types and Data Objects →  Types and Objects - Overview 

Data Objects

Data objects are instances of data types and contain the concrete data that a program uses at runtime. This is done by specifying data objects in operand positions.

Other versions: 7.31 | 7.40 | 7.54

Creating and Addressing Data Objects

The following objects are distinguished:

  • Named data objects, which are agreed statically using a data-defining statement and are addressed using a name. The typical data-defining statement is DATA. Named objects are created at the start of the lifetime of a context (a program, class, object, or procedure) by the ABAP runtime environment, and exist for as long as their context exists.
  • Literals, which are defined in the source code of a program and are fully defined by their value.

In addition to data objects declared in programs, there is a set of built-in data objects that can always be accessed in ABAP programs. Also, some statements create data objects implicitly, which are then available for special purposes. Examples include sum( ), cnt( ) in group level processing for extracts and title when selection screens are created.


Example

In the following example, dref is a named data object whose content points to an anonymous data object after the instance operator NEW is used. 555 is a numeric literal.

DATA dref TYPE REF TO i. 
dref = NEW #( 555 ).

Data Types of Data Objects

Every data object has a specific data type, and every data object uses memory to store the data. The data type of a data object is defined either with reference to a standalone data type or, when the data object is created, as a bound data type.

The data type of a data object is always defined uniquely at runtime of the program and cannot be changed. In the case of anonymous data objects, this data type determines the dynamic type of the related reference variables.


Example

In the following example, c_20 is a standalone data type used to declare the data object text1. The data object text2, on the other hand, has a bound data type.

TYPES c_20 TYPE c LENGTH 20. 
DATA: text1 TYPE c_20, 
      text2 TYPE c LENGTH 20.

Variable and Constant Data Objects

Variable data objects are distinguished from constant data objects. Variables can change their value at runtime. Constants always keep their initial value. Literals and text symbols are also constant. Input parameters in procedures are generally not modifiable either, if this would cause the assigned actual parameter to be changed.


Example

In the following example, true and false are constants that can be assigned to the variable flag.

TYPES bool TYPE c LENGTH 1.

CONSTANTS: true  TYPE bool VALUE 'X',
           false TYPE bool VALUE ' '.

DATA flag TYPE bool.

IF ...
  flag = true.
ELSE.
  flag = false.
ENDIF.

Static and Dynamic Data Objects

Static data objects, for which all technical attributes need to be defined when declared, are distinguished from dynamic data objects, whose memory requirement or size is not defined until runtime. Strings and internal tables are dynamic data objects.

After declaration, the length of a string is 0 and changes at runtime depending on the content assigned to it. When declared, internal tables do not contain any rows. Any number of rows is possible, and the rows are defined dynamically at runtime when the internal table is filled.

Structures that contain dynamic components are also dynamic data objects.


Example

In the following example, text_field is a static data object and text_string is a dynamic data object. When the system field sy-abcde is assigned to text_field, it is truncated from the tenth character. text_string is given all characters and has the same length as sy-abcde after the assignment.

DATA: text_field  TYPE c LENGTH 10, 
      text_string TYPE string. 

text_field  = sy-abcde. 
text_string = sy-abcde.

Flat and Deep Data Objects

All static data objects except reference variables are flat. Their content corresponds to the actual work data. Dynamic data objects and reference variables are deep and contain references that point to the actual content.The handling of references is implicit for dynamic data objects (strings and internal tables), and explicit for reference variables.

Structures that do not contain any deep components are flat structures. Structures that contain at least one deep component are deep structures.


Example

In the following example, struct1 is a flat structure and struct2 is a deep structure. In the flat structure, character-like components can be saved consecutively in the memory and substring access is possible. In the deep structure, the components contain pointers to the actual data and substring access is not possible.

DATA: 
  BEGIN OF struct1, 
    col1 TYPE c LENGTH 5 VALUE '12345', 
    col2 TYPE c LENGTH 5 VALUE 'abcde', 
  END OF struct1, 
  BEGIN OF struct2, 
    col1 TYPE string VALUE `12345`, 
    col2 TYPE string VALUE `abcde`, 
  END OF struct2. 

DATA(section1) = struct1+3(4).
DATA(section2) = struct2+3(4). "Syntax error

Continue

Byte Order

Alignment of Data Objects

Strings

References

Memory Management of Deep Objects