1. TYPES
type.
2. TYPES type(len).
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Implicit type specification notallowed and New naming convention.
TYPES type.
1. ... TYPE
type1
2. ...
LIKE f
3. ...
TYPE REF TO cif
4. ...
TYPE REF TO DATA
5. ...
TYPE LINE OF itabtype
6.
... LIKE LINE OF itab
7.
... DECIMALS n
8. ...
LENGTH n
9. ... DECIMALS n
Creates a new type with the name type. If you do not use
the TYPE addition, the new type has the default type C.
A type name can be up to 30 characters long. The name may only consist of alphanumeric characters and
the underscore character. It may not consist entirely of digits. Special characters such as German umlauts
are not allowed. As well as these characters, certain special characters are used internall.
However, these should not be used in application programs. SPACE
is a reserved name, and cannot therefore be used. Furthermore, you should not use a field in a statement
if it has the same name as one of the additions of the keyword (for example: PERFORM SUB USING CHANGING.).
Recommendations for Type Names:
... TYPE type1
The new type is defined by its type
type1. type1
may be one of the predefined types listed below, a type that you have defined yourself using
TYPES, or a type defined in the ABAPDictionary.
The default length (
DL) of the type type
depends on the type
type1.
Type
Description
DL Initial value
C
Character 1 Space
N
Numeric text 1 '00...0'
D
Date YYYYMMDD 8 '00000000'
T
Time HHMMSS 6 '000000'
X
Byte (heXadecimal) 1 X'00'
I
Integer 4 0
P
Packed number 8 0
F
Floating point number 8 '0.0'
STRING String
variable empty
string
XSTRING Byte sequence (X string) variable empty X string
The following
TYPES statement defines the type NUMBER as
a synonym for the type I (see also ABAP Numeric Types):
TYPES NUMBER TYPE I.
... LIKE f
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See LIKE reference to ABAP Dictionary types not allowed.
The new type is defined by the type of the field
f. f may be a field from the ABAP Dictionary or a fiedl in the program that has already been defined.
TYPES TABLE_INDEX_TYP LIKE SY-TABIX.
The type TABLE_INDEX_TYP refers to the type of the field
SY-TABIX (system field containing the index of an internal table).
It is often worth using this addition. If you do so, changes to the type of the field to which you are
referring are automatically reflected in your program. It also avoids unnecessary (and possibly unwanted) conversions at runtime.
... TYPE REF TO cif
The data type type is declared as a reference
in ABAP Objects. cif is
either a class or an interface. References
are used to type reference variables which, in turn, contain references (pointers) to objects.
References that refer to a class are called class references. Likewise, references that refer
to an interface are called interface references. Reference variables which are typed using class references
can contain object references to objects of that class. Reference variables which are typed using interface references can contain object references to objects whose class implements the interface.
Objects, that is, instances of classes are only addressed using reference variables. For creating objects,
see CREATE OBJECT.
INTERFACE I1.
METHODS M1.
ENDINTERFACE.
CLASS C1 DEFINITION.
PUBLIC
SECTION.
INTERFACES I1.
ENDCLASS.
TYPES: T_C1 TYPE REF TO C1,
T_I1 TYPE REF TO I1.
DATA: O1 TYPE T_C1,
O2 LIKE O1,
IR TYPE T_I1.
CREATE OBJECT O1.
O2 = O1.
IR
= O1.
CLASS C1 IMPLEMENTATION.
METHOD I1~M1.
...
ENDMETHOD.
ENDCLASS.
Handling Objects
... TYPE REF TO DATA
Declares the type type as a reference to a generic data object.
Variables with this type contain references (pointers) to data
objects. They can only be dereferenced using an ASSIGN statement.
TYPES: reftype TYPE REF TO DATA.
DATA: numref
TYPE reftype,
number TYPE I VALUE 123.
FIELD-SYMBOLS: <fs> TYPE ANY.
GET REFERENCE OF number INTO numref.
ASSIGN numref->* TO <fs>.
In this example, a reference is created to the data object number.
Subsequently, the data object is assigned to the field symbol <fs> using the dereferencing operator ->*. The field symbol can then be processed as usual.
... TYPE REF TO type
Data type for a typed reference variable. You can use: an elementary type; a type you defined yourself
using a
TYPES statement; or a type created in the ABAP
Dictionary. You can dereference a fully-typed data reference variable in any operand position, using the dereferencing operator, ->*.
types:
CNTREF type ref to I,
FLIGHTREF type ref to SFLIGHT,
LINEREF type CNTREF.
... TYPE LINE OF itabtype
The specified type itabtype must refer to the type of
an internal table (with or without header line). The system creates a type with the line type of the corresponding table type.
TYPES TAB_TYPE TYPE STANDARD TABLE OF I WITH NON-UNIQUE DEFAULT KEY.
TYPES MY_TYPE TYPE LINE OF TAB_TYPE.
The type MY_TYPE now has the same attributes as a line
of the table type TAB_TYPE, that is, type I.
... LIKE LINE OF itab
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See LIKE references to ABAP Dictionary types not allowed.
The data object itab must be an internal table (with or without a header line). The system defines a type with the line type of the corresponding table.
DATA TAB TYPE TABLE OF I.
TYPES MY_TYPE LIKE LINE OF TAB.
The type MY_TYPE has the same attributes as the line type
of the table TAB, that is, type I.
... LENGTH n
This addition is only permitted with the types
C, N, X,
and P. Creates a field of this type with a length of n.
... DECIMALS n
You can only use this addition with type P. It assigns
n decimal places to the field, which are used both in
calculations and for display. n must be between 0 and
14.
When you create a new program, the "Fixed point arithmetic" option is set by default. If
you switch this option off, the DECIMALS parameter is
not observed during calculations, but only when the field is displayed. It is then the responsibility
of the programmer to ensure that decimals are properly processed in calcuations by multiplying or dividing
by the relevant power of 10 (COMPUTE).
You are recommended always to work with fixed point arithmetic. When you do, the system performs
all calculations (including intermediate results) to the greatest possible accuracy (31 places).
For
information about when to use the fixed point type P and
the floating point type F, see ABAPNumeric Types.
TYPES type(len).
As in variant 1, except for the LENGTH addition.
Creates the type
type with the length len.
You can only use this variant with the types
C, N, P,
and X. Types that refer to another type can only be created in their default length (see table under effect of variant 1).
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Wrong
length specification in declaration.
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
Each byte may contain one character or two decimal or hexadecimal digits. In type
P fields, the system reserves one digit for the plus or minus
sign, so a P field with length 3 can contain a maximum
of 5 digits, while an X field with length 3 can contain 6. In both cases, the displayed length of the field is 6 characters.
Local Data Types in Programs