SAP DATA OBJECTS STRUCTURE



Get Example source ABAP code based on a different SAP table
  


VERSION 5 IN

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.
In ABAP Dictionary, structured types are DDIC structures or types of DDIC database tables
BEGIN_SECTION VERSION 5 OUT or of DDIC views
END_SECTION VERSION 5 OUT .
In ABAP CDS, CDS entities represent structured types.
The following sections give an overview of structures in ABAP.
ITOC

ABAP_PGLS
Names of Structure Components
Do not include components from structures
ABAP_PGL_END

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




Latest 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 and alignment gaps may occur.
The maximum number of bytes a structure can contain including alignment gaps is 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 use 8 bytes.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
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 (-).
ABEXA 00983
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
Deep structure. The following structure contains exclusively deep components.
ABEXA 00984
ABAP_EXAMPLE_END

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 AB_SQL also has an addition CORRESPONDING. The statement ASSIGN has a special variant COMPONENT OF STRUCTURE for dynamic access to structure components.

ABAP_EXAMPLE_VX5
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 (-).
ABEXA 00985
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
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 (->).
ABEXA 00986
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
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.
ABEXA 00987
ABAP_EXAMPLE_END

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 must be compatible in assignments and comparisons.
Substring access using offset/lengths is not possible for deep 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 work area of AB-SQL statements cannot contain any deep components other than strings or LOB handles.
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.



Latest notes:

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

ABAP_EXAMPLE_VX5
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
ABAP_EXAMPLE_END

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.
BEGIN_SECTION VERSION 5 OUT 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