Ansicht
Dokumentation

ABENDATA_OBJECTS - DATA OBJECTS

ABENDATA_OBJECTS - DATA OBJECTS

RFUMSV00 - Advance Return for Tax on Sales/Purchases   ABAP Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

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.

Creating and Addressing Data Objects

There is a distinction between:

  • Named data objects that are declared 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 framework and live for as long as their context exists.
  • Literals that 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. Furthermore, some statements create data objects implicitly that are then available for special purposes. Examples are sum( ), cnt( ) in group level processing for extracts and title when selection screens are created.

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 Types of Data Objects

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

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

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.

Variable and Constant Data Objects

Variable data objects are distinguished from constant data objects in how they can change. Variables can change their value at runtime. Constants always keep their initial value.

Literals and text symbols are also constant. Input parameters in procedures usually cannot be changed if this would cause the assigned actual parameter to be changed.

Immutable variables are a special kind of variables. To an immutable variable, a value can be assigned at exactly one write position of a context. Immutable variables are declared inline with the declaration operator FINAL(var)..Although one and the same declaration can appear only one time in a context, it can be processed several times - for example in a loop - and different values can be assigned then.

Note

Immutable variables can improve the robustness of programs whenever a variable should be filled at a write position only once and after that only read accesses should occur.

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 properties must 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.

The length of a string is 0 after declaration and changes at runtime depending on the content assigned to it. Internal tables do not contain any lines after their declaration. There can be any number of lines and the number is 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.

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 they contain references that refer 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.

In the following example, struct1 is a flat structure and struct2 is a deep structure. In the flat structure, character-like components are stored 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(section2) = struct2+3(4). "Syntax error






Vendor Master (General Section)   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.

Length: 9079 Date: 20240419 Time: 153057     sap01-206 ( 116 ms )