Definition of a structured data object

DATA - Definition of a Structured Data Object

Basic form

DATA: BEGIN OF struc,
...
END OF struc.

Effect

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

As well as the components in a structured field that you define, you can also include the elements of another structure using INCLUDE STRUCTURE. If you do not need any extra components of your own, 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 value "May".

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

If you use a structured field in statements designed for simple fields, the entire structure is treated as a field called struc with type C. However, you should not normally use a structured field as though it were a simple field, especially whenever the structure contains numeric fields (types I, P or F). The length of struc is the sum of the lengths of its components. Since some field types are aligned (to the ends of words, for example), the system inserts 'filler' fields in the structure before them. These also contribute to the total length of struc. For the same reason, you cannot specify the offset of a field by calculating the length of the components which precede it. However, the system guarantees that 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, wiht MOVE-CORRESPONDING).
INCLUDE s are aligned according to the maximum alignment of the components. This applies to INCLUDEs in both ABAP programs and in ABAP Dictionary structures.