Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Dynamic casting in field symbol assignment

Former Member
0 Likes
2,176

Dear experts,

I'm studying about dynamic casting with field symbols.

ASSIGN sy-datum TO <any> CASTING TYPE (typename).

Should the typename in my code above be a name of a type in the dictionary? I tried to use 'c' and 'i' as the value of typename (elementary type) but it raises run-time error.

Regards,

Haris

Dear experts,

I'm studying about dynamic casting with field symbols.

ASSIGN sy-datum TO <any> CASTING TYPE (typename).

Should the typename in my code above be a name of a type in the dictionary? I tried to use 'c' and 'i' as the value of typename (elementary type) but it raises run-time error.

Regards,

Haris

2 REPLIES 2
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,114

Press F1 on CASTING TYPE and you can find what it means

Read only

Former Member
0 Likes
1,114

Hi,

When the system accesses the field symbol, the content of the assigned data object is interpreted as if it had the type declared in the statement. After the TYPE addition, you can declare the name of a data object. The content of this data object indicates the data type at runtime.

TYPES: BEGIN OF t_date,
          year(4)  TYPE n,
          month(2) TYPE n,
          day(2)   TYPE n,
       END OF t_date.

FIELD-SYMBOLS: <fs> TYPE ANY,
               <f>  TYPE n.

ASSIGN sy-datum TO <fs> CASTING TYPE t_date.

WRITE / sy-datum.

[Click here|http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3930358411d1829f0000e829fbfe/content.htm] to know more