2007 Mar 14 9:18 AM
Hi all,
Can any one explain what is static and dynamic type reference variable in OOABAP. I didnt uderstand this statement can anyone explain this with an example.
obj1 type ref to class1
obj2 type ref to class2.
create object obj2.
obj1 ?= obj2. ****what does this statement mean.
Thanks,
Sam.
2007 Mar 14 9:30 AM
hi,
The static type is the type (class or interface) with which the reference variable has been typed.
DATA : oref type ref to c1. Static type of oref is pointing to class c1
The dynamic type is the class of the object to which the reference in a reference variable points.
CREATE OBJECT OREF . Dynamic type also points to c1
CREATE OBJECT OREF TYPE C2. Dynamic type points to subclass c2 of C1
If the static and dynamic types of a reference variable are different, the static type should always be more general than the dynamic type.
DATA:o_ref1 TYPE REF TO object,
o_ref2 TYPE REF TO class.
o_ref2 ?= o_ref1.
CATH SYSTEM-EXCEPTIONS move_cast_error = 4.
o_ref2 ?= o_ref1.
ENDCATCH."object(most general class) is the base class to all the classes and all other class(special classes) are subclasses of object.
In some cases, you may wish to make an assignment in which the static type of the target variable is less general than the static type of the source variable. This is known as a widening cast.
The result of the assignment must still adhere to the rule that the static type of the target variable must be the same or more general than the dynamic type of the source variable.
However, this can only be checked during runtime. To avoid the check on static type, use the special casting operator ?= and catch the potential runtime error move_cast_error
Hope this explaination helps.
Regards,
Richa.
Hi all,
Can any one explain what is static and dynamic type reference variable in OOABAP. I didnt uderstand this statement can anyone explain this with an example.
obj1 type ref to class1
obj2 type ref to class2.
create object obj2.
obj1 ?= obj2. ****what does this statement mean.
Thanks,
Sam.
2007 Mar 14 9:30 AM
hi,
The static type is the type (class or interface) with which the reference variable has been typed.
DATA : oref type ref to c1. Static type of oref is pointing to class c1
The dynamic type is the class of the object to which the reference in a reference variable points.
CREATE OBJECT OREF . Dynamic type also points to c1
CREATE OBJECT OREF TYPE C2. Dynamic type points to subclass c2 of C1
If the static and dynamic types of a reference variable are different, the static type should always be more general than the dynamic type.
DATA:o_ref1 TYPE REF TO object,
o_ref2 TYPE REF TO class.
o_ref2 ?= o_ref1.
CATH SYSTEM-EXCEPTIONS move_cast_error = 4.
o_ref2 ?= o_ref1.
ENDCATCH."object(most general class) is the base class to all the classes and all other class(special classes) are subclasses of object.
In some cases, you may wish to make an assignment in which the static type of the target variable is less general than the static type of the source variable. This is known as a widening cast.
The result of the assignment must still adhere to the rule that the static type of the target variable must be the same or more general than the dynamic type of the source variable.
However, this can only be checked during runtime. To avoid the check on static type, use the special casting operator ?= and catch the potential runtime error move_cast_error
Hope this explaination helps.
Regards,
Richa.
2007 Mar 14 12:01 PM
2007 Mar 14 12:20 PM
hi
good
go through this link,might help you to solve your problem
http://www.sappressbooks.com/downloads/h958_preview.pdf
thanks
mrutyun^
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |