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

Casting

Former Member
0 Likes
955

Hi,

Is it possible to cast a workarea to a type object like :

ASSIGN wa_alvdrag TO <object> CASTING TYPE object.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
838

Hi,

In ABAP a data type can be casted to data object and a object(class instance) caqn be cast to a class object, but you cannot cast a data type to a class object.

To quote from ABAP help

====

Assignment Rules for Reference Variables :

The content of a reference variable can only be assigned to another reference variable. Data references can only be assigned to data reference variables and object references can only be assigned to object reference variables. No conversion takes place in this type of assignment. In order for an assignment to take place, the static type of the target reference variable must be more general than or equal to the dynamic type of the source reference variable. After successful assignment, the target reference variable points to the same object as the source reference variable or the target reference variable adopts the dynamic type of the source reference variable.

====

Regards,

Saurabh

3 REPLIES 3
Read only

Former Member
0 Likes
838

Hi,

In general Casting is done where we use FIELD-SYMBOLS.

You can cast a workarea if your <object> is a FIELD-SYMBOL.

For further information Check this link which would be more helpful and gives you a clear picture.

http://abapprogramming.blogspot.com/2007/06/lesson-20-data-types-and-data-objects.html

Hope this would help you.

Regards

Narin Nandivada

Read only

Former Member
0 Likes
839

Hi,

In ABAP a data type can be casted to data object and a object(class instance) caqn be cast to a class object, but you cannot cast a data type to a class object.

To quote from ABAP help

====

Assignment Rules for Reference Variables :

The content of a reference variable can only be assigned to another reference variable. Data references can only be assigned to data reference variables and object references can only be assigned to object reference variables. No conversion takes place in this type of assignment. In order for an assignment to take place, the static type of the target reference variable must be more general than or equal to the dynamic type of the source reference variable. After successful assignment, the target reference variable points to the same object as the source reference variable or the target reference variable adopts the dynamic type of the source reference variable.

====

Regards,

Saurabh

Read only

Former Member
0 Likes
838

hI,

IF u use field symbols then u can use this

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 t_date.

ASSIGN sy-datum TO <fs> CASTING.

(or)

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.