SAP USING TYPES - Guide



Get Example source ABAP code based on a different SAP table
  



Using Types

ABAP_BACKGROUND
You can use the data types declared according to the rules on Bound and Standalone Data Types and Declaration of Data Types and Constants for declaring and creating data objects, as well as for typing field symbols or interface parameters. You specify them after the TYPE addition of the corresponding statement.

ABAP_RULE
Use semantically appropriate data types only
Use existing types only if they match the semantics of the typed object. You must not select an existing type based only on the technical properties.

ABAP_DETAILS
As long as it extends beyond an elemental ABAP type, the type of a data object or an interface parameter provides the source code reader with information about the semantics of these variables. This makes it easier to recognize the meaning of individual variables.
For this reason, you must use only data types whose semantics match the usage. The technical properties of a type alone do not justify its use in a specific context, as this impedes the readability of the program.
In particular, this applies to the reuse or multiple use of existing types. If you require a data type with specific technical properties for an application, you should not simply use any type with these properties from ABAP Dictionary. In the past, this has frequently been the chosen procedure. Consequently applying package encapsulation may help prevent the unwanted use of own data types.



Latest notes:

This rule applies especially for the use of structures from ABAP Dictionary. For example, you should never use a structure defining a database table as a template for input or output fields of classic dynpros or in Web Dynpro. This would violate the SoC principle.
ABAP_HINT_END

ABAP_EXAMPLE_BAD
In the following source code a variable is declared, whose name and use clearly indicate that it is used for a truth value. The variable is declared with a technically correct, but semantically incorrect, data type. syst-batch, after all, is the data type for the system field sy-batch, which indicates whether a program is executed in the background. DATA is_empty TYPE syst-batch.
...
IF is_empty IS INITIAL.
...
ENDIF.
ABAP_EXAMPLE_END

ABAP_EXAMPLE_GOOD
The following source code shows an improved example compared to the source code above. In this case, the abap_bool type of type pool abap, which is intended for truth values, is used. In addition, the request of the truth value is performed using a specifically designated constant from the same type pool. DATA is_empty TYPE abap_bool.
...
IF is_empty EQ abap_false.
...
ENDIF.
ABAP_EXAMPLE_END