ABAP Keyword Documentation → ABAP − Reference → Declarations → Declaration Statements → Data Types and Data Objects → Declaring Data Objects → DATA
DATA - BEGIN OF struc
Other versions: 7.31 | 7.40 | 7.54
Syntax
DATA BEGIN OF struc [READ-ONLY].
...
INCLUDE TYPE|STRUCTURE ...
...
DATA END OF struc.
Effect
Declares a new structure struc.
This starts with a DATA statement with the addition BEGIN
OF and must end with a DATA statement with the addition END OF.
The following can be included between these DATA statements:
-
Any
DATAstatements, in particular further closed structures. -
The statements
INCLUDE TYPEandINCLUDE STRUCTURE
The meaning of these statements is the same as in the definition of structured data types in the section
TYPES - BEGIN
OF, but here it is used to create a bound structured data type. No structure can be created without at least one component.
A component of type struc cannot be declared by referencing struc
itself. If the name struc is specified after LIKE in the declaration of a component, a search is performed for the next object with this name in a higher
visibility section, and used if found. If a more global object with this name does not exist, a syntax error occurs.
Notes
-
The addition
READ-ONLYcan only be used for whole structures and not for individual structure componentscomp. -
A structure called
textcannot have any components with three-character names, since these are reserved for addressing text symbols. It is best never to call a structuretextand avoid any conflicts with text symbols. -
The addition
BOXEDcannot be specified betweenDATA BEGIN OFandDATA END OFwhen declaring components. Static boxes in structures can only be defined withTYPES. -
The value
operator
VALUEcan be used to construct the content of structures. -
In an obsolete variant, text field literals
or the constant
spacecan be specified as anonymous components betweenBEGIN OFandEND OF. -
The use of the addition
OCCURSfor defining standard tables with structured row types is obsolete. -
The statements for declaring a structure are usually summarized in a chained statement if possible.
Example
In this example, a structure spfli_struc is declared with an elementary component
index and a substructure spfli_wa. The SELECT loop shows a possible use of the nested structure.
DATA: BEGIN OF spfli_struc,
index TYPE i,
spfli_wa TYPE spfli,
END OF spfli_struc.
SELECT *
FROM spfli
INTO @spfli_struc-spfli_wa.
spfli_struc-index += 1.
cl_demo_output=>next_section( |{ spfli_struc-index }| ).
cl_demo_output=>write_data( spfli_struc-spfli_wa ).
ENDSELECT.
cl_demo_output=>display( ).