2012 Oct 03 8:07 AM
the problem is to get the runtime information about the data type.
i have searched alot, got few answers but still have lots of confusion.
What i want,
at runtime i want to get the data type of entered value.
for eg,
if i enter value 3.4 --> it must return the data type p (NOT CHAR)!!
if i enter value 34 --> it must return numeric (type N)
if i enter value 3,4 --> it must return CHAR (type C).
What i have tried:
when variable p_data is given value 3.4
DATA P_DATA TYPE CHAR10.
DESCRIBE FIELD P_DATA TYPE TYP COMPONENTS COMP DECIMALS DEC
EDIT MASK MSK.
THE RESULT IS:
the variable TYP returning data type C(it should return p with deciamls1).why so?
using class CL_ABAP_TYPEDESCR.
CALL METHOD CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA
EXPORTING
P_DATA = P_DATA
RECEIVING
P_DESCR_REF = P_DESCR. "p_descr type ref to CL_ABAP_TYPEDESCR.
the result is:
same result as above. god knows why!
is there exists any fm or some class method which actually returns 3.4 as data type p decimals 1.
2012 Oct 03 9:30 AM
All those tools return the data definition, CHAR10 is character length 10, so you will never get anything else in returned parameters. They don't care of the actual data you put in this character field.
AFAIK there is not a such tool. (If anybody knows, please post an answer)
You should have to code yourself a recognition of the actual field content value, checking for non numeric characters, dot, comma, date separator and date plausibility...
Regards,
Raymond
2013 Feb 01 4:32 PM
Hi,
DATA lv_data TYPE i VALUE 34,
lv_type TYPE string,
lo_elem TYPE REF TO cl_abap_elemdecr.
lo_elem = cl_abap_typedescr=>describe_by_data( 'lv_data' ).
*data type can be found accessing the attribute type_kind of class cl_abap_elemdecr
lv_type = lo_elem->type_kind.
write lv_type.
2013 Feb 02 7:15 PM
Hi Ashish,
DATA lv_data TYPE i VALUE 34,
lv_type TYPE string,
lo_elem TYPE REF TO cl_abap_elemdecr.
lo_elem = cl_abap_typedescr=>describe_by_data( 'lv_data' ).
I presume the statement in bold will return the properties of the variable lv_data and not the property of the value it contains....please correct me if i am wrong
2013 Feb 02 5:21 PM
Hi Abhishek,
What you are trying to do is possible but you have to handle it yourself. There is no such standard method to identify the data type of the value entered in a variable.
I hope i understand what you are trying to do!!
2013 Feb 02 5:27 PM
Hi Aniket,
He is trying to find out data type of the data in variable at runtime, which is possible using RTTI with class cl_abap_typedescr and its subclasses.
Thank You.
2013 Feb 02 7:34 PM
Hi Ashish,
Yes i know he's trying to find the data type of the data in variable. So maybe the value which he's trying to export to the method is the data in the variable and not the variable, right??
CALL METHOD CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA
EXPORTING
P_DATA = P_DATA
RECEIVING
P_DESCR_REF = P_DESCR. "p_descr type ref to CL_ABAP_TYPEDESCR.
2013 Feb 02 7:51 PM
its really late out there. folks go get some sleep. w'll talk abt it later.
2013 Feb 02 8:05 PM
2013 Feb 15 9:37 AM
I too face the same issue,
I want to know the data type of a value entered in some parameter of type char