‎2008 Jun 30 7:39 PM
Hi,
Is it possible to cast a workarea to a type object like :
ASSIGN wa_alvdrag TO <object> CASTING TYPE object.
Thanks.
‎2008 Jul 01 6:02 AM
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
‎2008 Jun 30 8:09 PM
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
‎2008 Jul 01 6:02 AM
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
‎2008 Jul 02 5:32 AM
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.