SAP NEWS-46-ASSIGN-CASTING



Get Example source ABAP code based on a different SAP table
  



Casts to Any Data Type in ABAP Release 4.6A
The addition CASTING in ABAP_99A allows any memory area to be considered under the aspect of a particular type. This method of typing allows fields to be accessed symbolically instead of specifying offset and length, especially when implementing unions and containers. The following variants are possible:
Static cast with implicit type specification
Dynamic cast with explicit type specification
ITOC

ABAP_MODIFICATION_NN ASSIGN f TO <(><)> CASTING

In this static variant, the field symbol must be completely typed. The content of field f is interpreted in accordance with the type of the field symbol.

ABAP_MODIFICATION_NN ASSIGN f TO <(><)> CASTING TYPE type

Here, the field f is not handled in accordance with the type of the field symbol, but in accordance with the specified type (static variant). If the specified type CASTING TYPE (typename) is placed in parentheses, the content of the data object in the parentheses determines the data type at runtime (dynamic variant).

ABAP_MODIFICATION_NN ASSIGN f TO <(><)> CASTING LIKE field

In this case, field f is handled in accordance with the type of the field field (static variant). This variant is used dynamically by specifying a typed field symbol instead of the field field. Another option is, for example, to pass an untyped parameter in a FORM call. Here, the type of the passed actual parameter would be used at runtime.



Latest notes:

Typed field symbols should be used for performance reasons. The runtime of a typed ASSIGN statement is around 40 percent less than that required for an equivalent untyped ASSIGN statement.
ABAP_HINT_END