cancel
Showing results for 
Search instead for 
Did you mean: 

Get the type of a variable in ABAP

Former Member

Dear experts,

I've faced a problem in BW where I should get the type of a variable in ABAP. I need the type itself as a STRING to further processing.

How can I get this information?

Thanks in advance,

Simon

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member

Hi Simon,

You can use the RTTI classes to determine the 'type' of the 'variable' in ABAP. There is some documentation on this in ABAPDOCU.

An example from the documentation:

-


REPORT typedescr_test.

TYPES:

my_type TYPE i.

DATA:

my_data TYPE my_type,

descr_ref TYPE ref to cl_abap_typedescr.

START-OF-SELECTION.

descr_ref = cl_abap_typedescr=>describe_by_data( my_data ).

WRITE: / 'Typename:', descr_ref-> absolute_name.

WRITE: / 'Kind :', descr_ref->type_kind.

WRITE: / 'Length :', descr_ref->length.

WRITE: / 'Decimals:', descr_ref->decimals.

-


Best Regards,

Dabre

Former Member
0 Kudos

Hi Siggi,

Well, I need the data type itself furthermore I want to get the type of Infoobjects, for instance: 0version

For example:

DATA: l_var type /bi0/oiversion.

some_function(l_var) ==> '0version'.

Thanks,

Simon

Former Member
0 Kudos

Hi Simon,

well, if you know the name of the variable, you can read table rszglobv. There you get the infoobject the variable points to. With this information you can read table rsdiobj. For characteristics (basically thats what you get) read table rsdchabas and you get datatype and length, for keyfigures it's table rsdkyf.

Hope this helps!

regards

Siggi

Former Member
0 Kudos

Hi Simon,

what do you mean about the type? The data type itself, if it is a char, string, numc ...? Or are you talking about the value?

Please clarify.

Siggi