1. TYPES type.
2. TYPES type(len).
1. ... TYPE type1
2. ... LIKE f
3. ... TYPE REF TO cif
4. ... TYPE LINE OF itabtype
5. ... LIKE LINE OF itab
6. ... DECIMALS n
Creates a new type called type. If you do not use the TYPES
addition, the new type refers to the standard type C.
A type name may be up to 30 characters long. Apart from the
special characters '(', ')', '+', '.', ',', ':', '-', '<',
'>', you may use all other characters, including digits.
However, a type name may not consist entirely of digits.
Recommendations for type names:
The new type is defined by type type1. This can either be one of
the pre-defined types listed below, or a type of your own, defined
The length (SL) of type type is taken from type type1.
Type Type description Length Initial value
C Text (Character) 1 Space
N Numeric text 1 '00...0'
D Date (YYYYMMDD) 8 '00000000'
T Time (HHMMSS) 6 '000000'
X Hexadecimal 1 X'00'
I Whole number (integer) 4 0
P Packed number 8 0
F Floating point number 8 '0.0'
The following TYPES statment creates the type NUMBER as
a synonym for type I (see also ABAP number types):
TYPES NUMBER TYPE I.
The new type is defined through the type of field f. f can be a field from the ABAP Dictionary or a field that you have already defined in the program.
TYPES TABLE_INDEX_TYP LIKE SY-TABIX.
The type TABLE_INDEX_TYP now refers to the type of field SY-TABIX (index for internal tables).
Using this addition is very often the best way to define a type. It ensures that any type changes to fields to which you refer are automatically made in your program as well. This avoids any unnecessary (and maybe undesirable) type conversions.
Creates the new type type as an object or interface reference (according to whether cif is a class or an interface). Classes and interfaces are an essential part of ABAP Objects, the object-oriented extension of ABAP. Object and interface references are elementaty ABAP data types. The addition REF TO emphasizes the fact that they are only references. Data objects of this type are known as reference variables, and provide the only way of addressing objects (instances of classes). An object variable with type type can only point to instances of a class cif (objects), whereas an interface variable can point to all instances of the classes that implement the interface cif . For details of how to create instances of classes, see CREATE OBJECT.
INTERFACE I_TEST. METHODS METH. ENDINTERFACE. CLASS C_TEST DEFINITION. PRIVATE SECTION. INTERFACES I_TEST. ENDCLASS. TYPES: T_C_TEST TYPE REF TO C_TEST, T_I_TEST TYPE REF TO I_TEST. DATA: O_TEST_1 TYPE T_C_TEST, O_TEST_2 LIKE O_TEST_1, IF_TEST TYPE T_I_TEST. CREATE OBJECT O_TEST_1. O_TEST_2 = O_TEST_1. IF_TEST = O_TEST_1. CLASS C_TEST IMPLEMENTATION. METHOD I_TEST~METH. ... ENDMETHOD. ENDCLASS.
The type itabtype must be the type of an internal table either with or without header line. The system creates a type corresponding to the line type of the specified Table type.
TYPES TAB_TYPE TYPE I OCCURS 10. TYPES MY_TYPE TYPE LINE OF TAB_TYPE.
Type MY_TYPE now has the same attributes as a line of a
table with type TAB_TYPE, which is I.
The data object itab must be an internal table with or without header line. The system defines a type corresponding to the line type of the specified table.
DATA TAB TYPE I OCCURS 10. TYPES MY_TYPE LIKE LINE OF TAB.
The type MY_TYPE now has the same attributes as a line of a table with table type TAB, which is I.
You should only use this addition with data type P. A field with
this type has n decimal places in calculations and output, where n
is between 0 and 14.
Whenever you create a new program, the 'Fixed point arithmetic' attribute is selected by default. If you deselect this attribute, the DECIMALS specification applies only to output, not to calculations. In this case, you must ensure yourself that calculations have the right number of decimal places by multiplying or dividing by the appropriate powers of 10. (see COMPUTE).
SAP recommends that you always calculate using fixed point arithmetic. This ensures that intermediate calculations (division!) are also made to the greatest possible accuracy (31 decimal places).
To find out whether fixed point (type P) or floating point (type F) arithmetic is better in your particular case, see ABAP number types.
as in variant 1
Creates the type type with length len.
You cannot use this variant in conjunction with types C, N, P and X . Types that refer to another type can only be created with standard length (see table under variant 1).
The permitted lengths depend on the type to which you are referring:
Type Permitted length
C 1 - 65535
N 1 - 65535
P 1 - 16
X 1 - 65535
The system can store one character or two decimal or hexadecimal digits per byte. In P fields, one character is reserved for the sign, so a P field with length 3 can contain up to 5 digits, whereas an X field with the same length can contain 6. The output length of both fields is 6 characters.