SAP NEWS-46-ASSIGN-CASTING

Get Example source ABAP code based on a different SAP table
  



Casting to Any Data Type in Release 4.6A

The CASTING addition in ABAP_99A allows you to regard any memory area on the assumption that it has a particular type. This method of type specification allows you to address fields symbolically instead of specifying offset and length, especially for implementing unions and containers. The following variants are possible: Static cast with implicit type specification Dynamic cast with explicit type specification

ABAP_MODIFICATION_1 ASSIGN f TO <(><<)>fs> CASTING. In this static variant, the type of the field symbol must be fully specified. The contents of field f are interpreted according to the type of the field symbol.

ABAP_MODIFICATION_2 ASSIGN f TO <(><<)>fs> CASTING TYPE type. Here, the field f is not treated according to the type of the field symbol, but according to the type that you specify (static variant). If you enclose the CASTING TYPE (typename) in parentheses, the content of the data object in the parentheses determines the data type at runtime (dynamic variant).

ABAP_MODIFICATION_3 ASSIGN f TO <(><<)>fs> CASTING LIKE field. In this case, field f is treated according to the type of field <(><<)>field> (static variant). You can use this variant dynamically by specifying a typed field symbol instead of a field. Another possibility is, for example, to pass an untyped parameter in a subroutine call. Here, the type of the actual parameter would be used.



Latest notes:You should use typed field symbols for performance
reasons. The runtime of a typed ASSIGN statement is around 40 percent less than that required for an equivalent untyped ASSIGN statement.