... { }
| { CASTING [ {TYPE type|(name)}
| {LIKE dobj}
| {[TYPE p] DECIMALS dec}
| {TYPE HANDLE handle} ] }
| { obsolete_casting } ... .
Use casting_spec to determine with which data type the
memory area mem_area
assigned to the field symbol is treated if a statement contains the field symbol at an operand position.
You can either make no specification or use the addition CASTING.
Outside of classes, the obsolete variants obsolete_casting are also possible.
... { }
If you specify nothing for casting_spec, the field symbol
takes on the data type of the data object used in
mem_area and the assigned memory area is treated accordingly. This data type must be in accordance with the typing of the field symbol.
... CASTING ...
1. ... TYPE type|(name)
2. ... LIKE dobj
3. ... [TYPE p] DECIMALS dec
4. ... TYPE HANDLE handle
If you use addition CASTING in casting_spec, the memory area is treated as if it had the type specified by CASTING. When specifying CASTING, the field symbol cannot be typed with the obsolete addition STRUCTURE of the FIELD-SYMBOLS statement.
If none of the additions TYPE, LIKE or DECIMALS are specified after addition CASTING, the field symbol must be typed either completely or using one of the generic built-in ABAP types c, n, p, or x. The assigned memory area is casted to the type of the field symbol. The specified data type has to match the generic typing of the field symbol; in other words, the casting can specify the generic typing, but not generalize it.
If one of the additions TYPE,
LIKE or DECIMALS is specified after addition
CASTING, the field symbol must be only generically, rather than completely, typed. The assigned memory area is casted to the specified type. The specified data type must match the generic
typing of the field symbol, which means that the
casting may specialize the generic typing, but not generalize it.
If the data type specified by CASTING is
deep, the deep components have to appear in the assigned memory area in exactly the same way in terms of type and position. In particular, this means that individual
reference variables can be assigned to only one field symbol that is typed as a reference variable by the same
static type.
... TYPE type|(name)
After TYPE, you can specify either a data type type directly, or a character-type data object name in brackets, which must contain the label of a data object during execution. The data type specified after TYPE can be generic. However, you cannot specify table types or REF TO.
If a generic character-type c or
n is specified after TYPE, the length of the
assigned memory area must be a multiple of the length of a character in the memory when the statement is executed in Unicode programs.
... LIKE dobj
After LIKE, you must specify a data object directly. For the casting, the data type of the data object is used. Within a
procedure, you must not specify a completely generically typed formal parameter for dobj.
Besides the public attributes of its own program, the public attributes of global classes are also among the data objects that can be referenced using LIKE.
... [TYPE p] DECIMALS dec
After DECIMALS, you must specify a numeric data object
dec. For the casting, the data type p is used; the size of the
fractional portion is determined by the content of dec. The size of the fractional portion must not exceed the number of
decimal places. For
DECIMALS, you need not specify TYPE. If you
use TYPE, you can specify only the data type p, which is used anyway.
Calculating the quotient from the packed number pack and the field symbol <pack> demonstrates the effect of casting with addition DECIMALS. Factors between 10 and 100,000,000 are determined. When using <pack> in operand positions, a different value is used as when using pack.
DATA factor TYPE p DECIMALS 0.
DATA pack TYPE p DECIMALS 0 VALUE '12345678'.
FIELD-SYMBOLS <pack> TYPE p.
DO 8 TIMES.
ASSIGN pack TO <pack> CASTING DECIMALS sy-index.
factor = pack / <pack>.
WRITE / factor.
ENDDO.
... TYPE HANDLE handle
Use addition HANDLE to use a data type for the casting that is described by a
type object of
RTTS. For handle,
you must specify a static type reference variable of class CL_ABAP_DATADESCR
or its subclasses, which points to a type object. The type object may have been created from existing data objects or by defining a new data type, using the methods of RTTS.