SAP BOUND INDEPENDENT DTYPE - Guide



Get Example source ABAP code based on a different SAP table
  



Bound and Standalone Data Types

ABAP_BACKGROUND
A bound data type only exists as a property of a data object. It is created when a data object is not declared using a reference to a standalone data type that defines all technical properties, but when technical properties are defined in the statement DATA instead. Here DATA is used as a synonym for all statements that declare data objects. The resulting type is a property of the declared variable and it is bound to this variable. If this type is needed in several different places, it has to be defined separately for each place where it is used.
A standalone data type is declared in the ABAP Dictionary or using the statement TYPES and defines all technical properties of a data object with one exception: When table types are defined, they can be generic with respect to the keys specified. A standalone generic type can only be used for typing but not for data declarations. However, there is one exception: In a DATA statement, the standard key is added to the generic standard table type.

ABAP_RULE
Use standalone data types
Use standalone data types instead of constructing bound data types when declaring data objects.

ABAP_DETAILS
Here is a list of reasons that support the declaration of standalone types:
The declaration of a standalone data type allows multiple data objects (or interface parameters or field symbols) to use a type without the need to always redefine this type.
Even if only one data object of this type is required initially, it is very likely that further data objects will be added during the course of the development. If the type needs to be adapted later on, you can do this centrally.
Declaring a standalone type and using it to declare a data object is nothing more than following the rule for the SoC principle.
The data type should always have a specific meaning and a meaningful name. This gives data types a clear semantic meaning and makes the program easier to read and understand. Therefore, you should declare different data types for technically identical but semantically different data objects. This also increases the probability that a type can be adapted later on without making major program changes.
Therefore you should avoid declaring purely technical data types that cannot be associated with specific semantics, because this does not make it easier to read or enhance the program.



Latest notes:

A separate rule specifies where the standalone data types should be declared.
ABAP_HINT_END

ABAP_EXAMPLE_BAD
The following source code shows the declaration of two data objects that are supposed to have the same data type. However, the technical properties, length, and number of decimal places are defined as standalone, bound data types in the DATA statements in question. ...
DATA number_1 TYPE p LENGTH 6 DECIMALS 2.
DATA number_2 TYPE p LENGTH 6 DECIMALS 2.
...
ABAP_EXAMPLE_END

ABAP_EXAMPLE_GOOD
The following source code moves the definition of the technical properties of the data objects in the above example to a separate TYPES statement. The standalone data type is only declared once and can then be used multiple times. TYPES number_type TYPE p LENGTH 6 DECIMALS 2.
...
DATA: number_1 TYPE number_type,
number_2 TYPE number_type.
...
ABAP_EXAMPLE_END