Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Declarations →  Declaration Statements →  Data Types and Data Objects →  Declaring Data Types →  TYPES →  TYPES - BEGIN OF struct_type 

INCLUDE - TYPE, STRUCTURE

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


INCLUDE { {TYPE struc_type} 
        | {STRUCTURE struc} }
        [AS name [RENAMING WITH SUFFIX suffix]].

Extras

1. ... AS name
2. ... RENAMING WITH SUFFIX suffix

Effect

This statement can only be declared within a structure definition with the additions BEGIN OF and END OF of the statements TYPES, DATA, CLASS-DATA, and STATICS. It applies all the components of a structured type at the specified location to the current structure definition. The structured type can be specified as follows:

  • As a structured data type struc_type after TYPE, both visible and usable in this place. struc_type can be a local structured type, a visible structured type of a global class or global interface, or a structure from ABAP Dictionary.
  • As a structured data object struc after STRUCTURE, visible in this place. Its structured data type is used. struc must be a structure of the same program or a visible attribute of a global class or global interface.

The INCLUDE statement does not create a substructure, which means the components are inserted as if they are included individually in place of the statement INCLUDE.


Notes

  • The statement INCLUDE described here should no longer be used for the following reasons:

  • If further structure components are to be added to existing components using the statement INCLUDE or if multiple INCLUDE statements are used in a structure, this can produce syntax errors due to naming conflicts. This is particularly problematic if structures that are not defined in the same program are included and these are to be changed at a later date.

  • The included structures cannot be addressed as such without restrictions.

  • The necessary metadata is stored again for each component of an included structure, whereas the metadata for the components of a substructure is only stored once when the substructure is defined.

  • In contrast to real substructures, structures included using INCLUDE cannot be declared as static boxes when embedded.
Where possible, real substructures should be created rather than using the statement INCLUDE. The addition RENAMING WITH SUFFIX, however, should be used to prevent naming conflicts. This recommendation also applies to includes of structures in ABAP Dictionary, where the structures of database tables in particular cannot contain any real substructures.
  • As usual, the addition TYPE is used to specify a data type. Like the addition LIKE, the addition STRUCTURE is used to specify a data object. Outside of ABAP objects, flat structures, database tables, or views in ABAP Dictionary can also be specified for struc with the addition STRUCTURE.
  • In constant structures defined with CONSTANTS, no components can be included using INCLUDE because these cannot be assigned a start value.
  • With respect to their alignments, structures included using INCLUDE behave like substructures, which means alignment gaps can occur before the first or after the last component. These do not occur when the components are declared directly.
  • A structure that is included using INCLUDE is handled by the method GET_COMPONENTS of the class CL_ABAP_STRUCTDESCR of RTTI in the same way as a substructure. The returned component table only contains one row for an included structure. The component type is represented by an object from CL_ABAP_STRUCTDESCR, but the AS_INCLUDE column contains the value "X". The method GET_INCLUDED_VIEW_TAB can be used to resolve the components of included structures.
  • When a static box is applied from one structure to another, its boxed component attribute is also applied.

Addition 1

... AS name

Effect

By specifying the name name after the addition AS, either all components of the included structure struc_type or struc can be addressed together using the name name, or individual components can be addressed using the structure component selector (-). The name name must be unique within the structure in which the components are included. This means that there can be no other component with this name and it cannot be specified in a different INCLUDE statement after AS.


Notes

  • Included components for which a name is specified after AS can be addressed in the same way as if they were components of a substructure name.
  • A name name specified with AS name is used only as an additional explicit addressing option and is ignored by implicit addressings in statements such as MOVE-CORRESPONDING or SELECT INTO CORRESPONDING. A component renamed using RENAMING WITH SUFFIX actually has this name and is therefore never ignored.

Addition 2

... RENAMING WITH SUFFIX suffix

Effect

The addition RENAMING WITH SUFFIX is used to rename each individual component by adding the extension suffix, which prevents naming conflicts between components of the same name. suffix must be specified directly.


Note

Using the RENAMING WITH SUFFIX addition makes it possible to embed an individual structure multiple times.


Example

In this example, the structure week is defined by repeatedly using the components of the structured type t_day. The components of week are all at the same level and can be addressed as follows: week-work_mon, week-free_mon, week-work_tue, and so on. Alternatively, they can also be addressed as follows: week-monday-work, week-monday-free, week-tuesday-work, and so on.

TYPES: BEGIN OF t_day, 
         work TYPE c LENGTH 8, 
         free TYPE c LENGTH 16, 
       END OF t_day. 

DATA BEGIN OF week. 
  INCLUDE TYPE t_day AS monday    RENAMING WITH SUFFIX _mon. 
  INCLUDE TYPE t_day AS tuesday   RENAMING WITH SUFFIX _tue. 
  INCLUDE TYPE t_day AS wednesday RENAMING WITH SUFFIX _wed. 
  ... 
DATA END OF week.