What does it do? The specification casting_spec> defines the data type used to handle the memory area mem_area> > assigned to the field symbol when a statement contains the field symbol in an operand position. Either the addition CASTING> can be specified or nothing at all. BEGIN_SECTION VERSION 5 OUT Outside of classes, the obsolete variants obsolete_casting>> are also possible. END_SECTION VERSION 5 OUT The following restrictions apply:
In assignments of table expressions>, only the first alternative can be used without further additions.
The CASTING> addition cannot be used for enumerated types>. This means that the assigned memory area must not be an enumerated object> and the specified data type must not be an enumerated type.
ABAP Alternative 1 ... ${ $}>
What does it do? If nothing is specified for casting_spec>, the field symbol inherits the data type of the data object used in mem_area>> and the assigned memory area is handled accordingly. This data type must match> the typing > of the field symbol.
ABAP_EXAMPLE_VX After the first assignment the field symbol has type c> of length 3 and after the second assignment the field symbol has type string >. The statement DESCRIBE FIELD>> returns the corresponding values C 3> and g>. ABEXA 00016 ABAP_EXAMPLE_END
ABAP_EXAMPLE_V5 After the first assignment the field symbol has type c> of length 3 and after the second assignment the field symbol has type string >. The statement DESCRIBE FIELD>> returns the corresponding values C 3> and g>. ABEXA 01614 ABAP_EXAMPLE_END
ABAP Alternative 2 ... CASTING ...>
ABAP Addition 1 ... ${ $}> 2 ... TYPE type$|(name)> 3 ... LIKE dobj> 4 ... $[TYPE p$] DECIMALS dec> BEGIN_SECTION VERSION 5 OUT 5 ... TYPE HANDLE handle> END_SECTION VERSION 5 OUT
What does it do? If the addition CASTING> is used in casting_spec>, the memory area is handled as if it had the type specified by CASTING >. BEGIN_SECTION VERSION 5 OUT If CASTING> is specified, the field symbol cannot be typed using the obsolete addition STRUCTURE> of the statement FIELD-SYMBOLS>>. END_SECTION VERSION 5 OUT Casting can either take place implicitly using the typing of the field symbol or explicitly using one of the additions TYPE>, LIKE> , or DECIMALS>. In explicit castings, the field symbol can only be typed generically, not completely.
Latest notes:
If the data type determined by CASTING> is deep> or if deep data objects are stored in the assigned memory area, the deep components must appear with exactly the same type and position in the assigned memory area. 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 >.
If the addition CASTING> is used, the result of the statement ASSIGN> may be platform-dependent. The internal byte order> of characters can, for example, be platform-dependent, which becomes apparent in a cast to a byte-like data type.
The memory area mem_area>> must meet the alignment requirements> of the data type specified by the casting. When flat elementary data types are specified, for example, the memory address mem_area> must be divisible as follows:
By 2 for the character-like data types c> and n> and the date/time types d> and t>.
By 4 for the numeric data type i>.
By 8 for the numeric data types int8>, f>, and decfloat16>.
By 8 for the time stamp type utclong>.
By 16 for the numeric data type decfloat34>.
The static check of the statement ASSIGN> using the addition CASTING> is performed so that all errors are identified, regardless of the system or platform on which the check is run. A runtime check only checks the current system or the current platform. NON_V5_HINTS
These checks also always take place if the field symbol <(><<)> fs>> is typed with the obsolete addition STRUCTURE> of the statement FIELD-SYMBOLS>. ABAP_HINT_END
ABAP Addition
What does it do? If the addition CASTING> is specified without further additions, the assigned memory area is cast to the type of the field symbol. The field symbol must be either completely typed or with one of the generic built-in ABAP types c>, n>, p>, or x>.
ABAP_EXAMPLE_VX5 Casting of the integer 333 as a byte field. Depending on the byte order>, the output is either 4D01 > or 014D>. ABEXA 00017 ABAP_EXAMPLE_END • TYPE ASSIGN CASTING
ABAP Addition
What does it do? Explicit specification of a data type after TYPE>. The name of the type can be specified as follows:
type> Direct static specification as type>.
(name)> Specification as the content of a character-like data object name> that contains the name of a data type in uppercase letters when the statement is executed. The following can be specified for name>:
Literal or constants
If the data object name> is specified as a character literal or as a constant, it can be evaluated statically, and the specified type is recognized as the used object.
Variable BEGIN_SECTION ID ASSIGN-CASTING-DYNAMIC-TYPE
If the data object name> is specified as a variable, it is specified only dynamically, and the content is not evaluated statically. END_SECTION ID ASSIGN-CASTING-DYNAMIC-TYPE When the statement is executed, name> is not evaluated until runtime in both cases. The assigned memory area is cast to the specified type. The data type specified after TYPE> cannot be generic, apart from the built-in ABAP types c>, n>, p>, and x>. Furthermore, table categories> and REF TO> cannot be specified.