Elementary data types and data objects in a local program are exclusively defined and declared by reference to known data types and data objects (see: Statements TYPES and DATA). If you use the addition TYPE, you can either reference to an inbuilt ABAP type, a predefined elementary type in the local program, or to a data element defined in the ABAP Dictionary. If you use a LIKE reference, dobj can be an existing data object with an elementary data type. If you do not use the TYPE or LIKE addition, the system uses the default predefined type c. However, you should always use the explicit statement. Especially the short form is not allowed within classes.
Elementary local data types in a program make your programs easier to read and understand. If you have used such a type to define several data objects, you can change the type of all of those objects in one place, just be changing the definition in the TYPES statement. Alternatively, if you use a set of data types regularly in different programs but do not want to store them in the ABAP Dictionary, you can create an include program for the type definitions, and incorporate this into the relevant programs.
number TYPE i,
length TYPE p DECIMALS 2,
code(3) TYPE c.
In this example, a data type called NUMBERis defined. It is the same as the predefined data type i, except it has a different name to make the program easier to read.
The program defines a data types LENGTH,based on the generic ABAP type p. LENGTH is defined with a given number of decimals. If it becomes necessary to change the accuracy of length specifications, for example, you only have to change the TYPESstatement in the program.
A third data type, CODE, is also defined. CODE is based on the predefined generic ABAP type c. The length is defined as 3 bytes.
DATA counts TYPE i.
company TYPE spfli-carrid,
no_flights LIKE counts.
This example shows how you can use the TYPE addition to refer to a column (CARRID) of a database table (SPFLI). The LIKE addition refers to an existing data object.
TYPES mytext TYPE c
TYPES myamount TYPE p DECIMALS 2.
DATA text TYPE mytext.
DATA amount TYPE myamount.
text = ' 4 / 3 = '.
amount = 4 / 3 .
WRITE: text, amount.
This program produces the following output on the screen:
4 / 3 = 1.33
The program uses the TYPESstatement to create the local data types mytext and myamount. The technical attributes are defined with reference to predefined ABAP types. Then, the data objects text and amount are declared with the DATA statement. Their data types are defined with reference to mytext and myamount. Values are assigned to the data objects and the contents of the data objects are displayed on the screen.