‎2006 Nov 22 6:09 PM
Hi,
i want to get the type of a variable. For example, the following code :
data: my_var type zmystruct.
In ABAP, i want to get type 'zmystruct' and after to create dynamically a new variable of this type.
Thanks for help.
‎2006 Nov 22 6:18 PM
HI
**** Get type object from a data object
DATA: DATATYPE TYPE REF TO CL_ABAP_DATADESCR,
FIELD(5) TYPE C.
DATATYPE ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( FIELD ).
* For stucture
DATA: LINETYPE TYPE REF TO CL_ABAP_STRUCTDESCR,
MYSTRUC TYPE SPFLI.
* Get Structure of Some Database Table for example
LINETYPE ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( MYSTRUC ).
Write: DATATYPE->TYPE_KIND,
LINETYPE->TYPE_KIND,
LINETYPE->ABSOLUTE_NAME.
Raja T
Message was edited by:
Raja T
‎2006 Nov 22 6:22 PM
‎2006 Nov 22 6:23 PM
HI,
You use the following syntax to define reference types:
<b>TYPES dtype {TYPE REF TO type}|{LIKE REF TO dobj}.</b>
The syntax for a direct declaration of a reference variable is as follows:
<b>
DATA ref {TYPE REF TO type}|{LIKE REF TO dobj}.</b>
The addition REF TO defines a data type dtype for a reference variable and declares the reference variable ref. The specification after REF TO specifies the static type of the reference variable. The static type constricts the object set to which a reference variable can point. The dynamic type of a reference variable is the data type and the class of the object respectively, to which it currently points. The static type is always more universal or equal to the dynamic type
You can use the TYPE addition to define data types for data and object reference variables. The LIKE addition exclusively defines data types for data reference variables.
The syntax and meaning of the additions TYPE and LIKE are completely equal for both statements with the exception that TYPES creates an independent reference type, whereas DATA creates a bound reference type.
Regards
Sudheer
‎2006 Nov 22 6:46 PM
There's a very good tutorial on creating dynamic objects here. It will take a few minutes to get through it, but it is worth the read.
‎2006 Nov 22 11:49 PM
if it really is a simple case of creating variables like others then you can do this:
DATA my_dref TYPE REF TO data.
FIELD-SYMBOLS <struc> TYPE ANY.
CREATE DATA my_dref type zmystruct.
ASSIGN my_dref->* TO <struct>.
*Field symbol <struct> is now an instance of zmystruct.
or
CREATE DATA my_dref like my_var.
ASSIGN my_dref->* TO <struct>.