Ansicht
Dokumentation

ABENDATA_OBJECTS_STRUCTURE - DATA OBJECTS STRUCTURE

ABENDATA_OBJECTS_STRUCTURE - DATA OBJECTS STRUCTURE

TXBHW - Original Tax Base Amount in Local Currency   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.
SAP E-Book

Structures

Structures are data objects that consist of components of any data type that are stored consecutively in the memory. The data type of a structure is a structured type:

  • In a program, a structured type or structure is created using the additions BEGIN OF ... END OF of the statements TYPES, DATA, and so on. Structured types can also be created dynamically using the RTTC methods.

The following sections give an overview of structures in ABAP.

Kinds of Structures

Depending on the type of component, structures are named as follows:

  • Flat structures do not contain any deep components. They only contain components with flat data types, such as elementary types c, n, d, t, decfloat16, decfloat34, f, b, s, i, int8, p, x, utclong, or structures with these types.
  • Flat character-like structures are flat structures with exclusively character-like components.
  • Nested structures contain at least one substructure. Whether a nested structure is flat or character-like depends on the attributes of all components.
  • Deep structures contain at least one deep component in any nesting level. Possible deep components include strings, internal tables, boxed components, data or object references.

A structure that contains static or dynamic components is formally also a static or dynamic data object, respectively.

The following figure illustrates a deep structure.

IMAGE @@ABDOC_Deep_Structure.gif@@567@@255@@

Notes

  • The term "nested structure" must not be confused with the term "deep structure". A nested structure is flat if it contains exclusively flat components and subcomponents. A nested structure is deep when it has at least one deep component or subcomponent.
  • Generally, the components of a structure are not stored directly one after the other in memory, but alignment gaps may occur.
  • The maximum number of bytes a structure can contain including alignment gaps corresponds to the maximum length of a field of type x, which is stored in the constant TYPE_X_MAX_LENGTH of the class CL_ABAP_ELEMDESCR. Components that are reference variables, strings or internal tables each contribute 8 bytes.

Example

Nested structure. The substructure is created using a reference to the DDIC structure SCARR for the second component. The components are accessed using the structure component selector (-).

Example

Deep structure. The following structure contains exclusively deep components.

Use of Structures

Structures are addressed either completely or by component in appropriate operand positions. The structure component selector (-) is used for the latter. In the case of data reference variables that are typed as a structure, the components of the structure to which the data reference variable points can also be addressed using the object component selector (->).

Special conversion and comparison rules apply to assignments that involve structures. Flat character-like structures have the special feature that they can be used like character-like data objects in many operand positions and included in the generic ABAP type clike. They can be specified in almost all operand positions where elementary character-like data objects are possible. The ABAP runtime framework then interprets the structure as an elementary field of the type c in the length of the structure. An exception to this are operand positions of string expressions and string functions with named arguments.

For the assignment of structure components, there is a special statement MOVE-CORRESPONDING, a constructor operator CORRESPONDING, and a system class CL_ABAP_CORRESPONDING. The INTO clause of also has an addition CORRESPONDING. The statement ASSIGN has a special variant COMPONENT OF STRUCTURE for dynamic access to structure components.

Example

Inline declaration of a structure wa in a SELECT statement with reference to the DDIC database table SCARR. The components of the structure are accessed using the structure component selector (-).

Example

Creation of a structure as an anonymous data object with the type of the DDIC database table SCARR in the ABAP Dictionary to which the data reference variable dref points. Used as the target area of a SELECT statement using the dereferencing operator (->*). The components of the structure are accessed using the object component selector (->).

Example

The following example demonstrates that a flat structure with exclusively character-like components can behave like a structure and like a character-like data object.

Use of Deep Structures

Since the data content of deep structures is not stored completely within the memory bounds of the structure itself and the deep components are just references to the actual data instead, there are some general restrictions apply when using deep structures, as opposed to flat structures:

  • Deep structures cannot be used as character-like data objects in operand positions and are not included in the generic ABAP type clike. This applies in particular to structures that contain strings.
  • When data objects are cast with ASSIGN, the deep components of deep structures must match in type and position in the type of the data object, and in the type of the field symbol.
  • The target or source field of the statements OPEN DATASET and TRANSFER cannot be a deep structure.
  • No internal tables with a deep line type can be passed to a TABLES parameter in a remote function call. Deep structures can be passed to the other parameters, as long as they do not contain any reference variables.

Note

These restrictions are particularly important if single components in existing flat character-like structures are converted to strings, which makes the entire structure deep.

Example

The following two deep structures are not compatible and cannot be converted to each other.

DATA:
  BEGIN OF struct1,
    col1 TYPE c LENGTH 4,
    col2 TYPE REF TO data,
  END OF struct1,
  BEGIN OF struct2,
    col1a TYPE c LENGTH 2,
    col1b TYPE c LENGTH 2,
    col2 TYPE REF TO data,
  END OF struct2.

struct1 = struct2. "Syntax error

Use of Deep DDIC Structures

The same restrictions apply to deep DDIC structures defined in the ABAP Dictionary as to deep structures declared in ABAP programs. Further restrictions apply only when the following language elements that are forbidden in classes in which only flat ABAP Dictionary structures can be specified are used:

  • Statement TABLES for table work areas.
  • Obsolete use of LIKE instead of TYPE as a reference to data types in the ABAP Dictionary in type declarations and typings

These language elements are forbidden in classes.

Boxed Components

The substructures of nested structures and structured components of classes or interfaces can be declared as boxed components.






ABAP Short Reference   BAL Application Log Documentation  
This documentation is copyright by SAP AG.

Length: 13232 Date: 20240329 Time: 114544     sap01-206 ( 161 ms )