*&———————————————————————*
*& Report ZTEST_FIELD_SYMBOL
*& Tang Can
*&———————————————————————*
*& Test Field symbo
*&———————————————————————*
REPORT ZTEST_FIELD_SYMBOL.
* define my teype
TYPES: typ_mine(10) type c.
* define Data type
DATA:
smallfield(5) type c,
largefield(15) type c VALUE ‘123456789012345′,
typename(8) type c value ‘TYP_MINE’,
sometype type REF TO CL_ABAP_TYPEDESCR,
rrt_type TYPE REF TO CL_ABAP_DATADESCR.
FIELD-SYMBOLS: TYPE any, type typ_mine.
* type==>type
ASSIGN largefield to CASTING.
WRITE:/ ‘Casting from 15==>10 to :’, .
ASSIGN largefield to CASTING type typ_mine.
WRITE:/ ‘Casting from 15==>10 to ,”Casting type to typ_mine” in Field-symbol:’, .
ASSIGN largefield to CASTING type n.
WRITE:/ ‘Casting from 15==>n to ,”Casting type to N” in Field-symbol:’, .
ASSIGN largefield to CASTING type (typename).
WRITE:/ ‘Casting from 15==>10 to ,”Dynamically Casting type to typ_mine” in Field-symbol:’, .
sometype = cl_abap_typedescr=>DESCRIBE_BY_NAME( ‘TYP_MINE’ ).
“ASSIGN largefield to CASTING TYPE HANDLE sometype.
rrt_type ?= sometype.
ASSIGN largefield to CASTING TYPE HANDLE rrt_type.
WRITE:/ ‘Casting from 15==>10 to ,”using CL_ABAP_TYPEDESCR” in Field-symbol:’, .
ASSIGN largefield to CASTING LIKE smallfield.
WRITE:/ ‘Casting from 15==>5 to ,”Like Smallfield” in Field-symbol:’, .
ASSIGN largefield to CASTING LIKE .
WRITE:/ ‘Casting from 15==>5 to ,”Like ” in Field-symbol:’, .