DATA - Definition of a Structured Data Object

Basic form

DATA: BEGIN OF struc [READ-ONLY],
         ...
      END   OF struc.

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use Operational Statements in Structure Definitions und Cannot Use Anonymous Components in Structures.

Effect

The structured field struc is defined, and all of the fields defined between " BEGIN OF struc" and "END OF struc" are combined into the structure struc. The field names are always prefixed by "struc-". You can nest structured fields to any depth (see also Data Objects).

The READ-ONLY condition is only possible in the public visibility section of a class and it sets the external changeability of the whole structure

Note

You can also declare structured fields with reference to existing structures using the TYPE and LIKE additions.

If, for a structured field, you require components of a predefined structure as well as your own components, you can use INCLUDE STRUCTURE to include them. If you do not need any extra components of your own, however, it is better to use a LIKE reference.

Example

DATA: BEGIN OF PERSON,
        NAME(20) VALUE 'May',
        AGE TYPE I,
      END   OF PERSON.
PERSON-AGE = 35.

The field PERSON-NAME now has the content "May".

DATA: BEGIN OF PERSON1,
        VORNAME(20) VALUE 'Michael'.
        INCLUDE STRUCTURE PERSON.
DATA  END   OF PERSON1.

Notes

  1. Do not confuse the above variant with the following variant, which is used to define an internal table with a header line.

         BEGIN OF itab OCCURS n,
           ...
         END   OF itab.



Notes

  1. If you use a structured field in statements designed for simple fields, the entire structure is treated as a struc field with type C. However, you should not use a structured field as single field, especially if the structure contains numeric fields (types I, P or F). The length of struc is therefore not the sum of the lengths of its components. Since some field types have to be aligned, the system inserts filler fields before them in the structure. These filler fields also contribute to the total length of struc. For the same reason, you cannot specify the offset of a field to the start of the structure by calculating the length of the components that precede a specific component in the structure. However, two fields with the same structure are always identical, even down to their filler fields. This means that you can always compare these fields and assign one to the other (MOVE, IF and so on) without having to work field by field (for example, with MOVE-CORRESPONDING).
    INCLUDEs are aligned according to the maximum alignment of the components. This applies to INCLUDEs in both ABAP programs and ABAP Dictionary structures.


  2. When you use the TABLES statement, the system also creates a structured field, known as the table work area. In ABAP it is virtually obsolete and is only needed for communication with screens.

Additional help

Variables