2009 Jan 16 2:00 PM
Hello all,
we have a datafield defined as ANY. This datafield can contain a REF TO DATA to an internal table or a TABLE. Is there a way in ABAP to distinguish at runtime what is in this field?
Thanks in advance
Best regards Dominik
Edited by: Dominik Deimling on Jan 16, 2009 3:00 PM
Hello all,
we have a datafield defined as ANY. This datafield can contain a REF TO DATA to an internal table or a TABLE. Is there a way in ABAP to distinguish at runtime what is in this field?
Thanks in advance
Best regards Dominik
Edited by: Dominik Deimling on Jan 16, 2009 3:00 PM
2009 Jan 16 2:25 PM
For this the Runtime type services are available.
Superclass CL_ABAP_TYPEDESCR and all of its subclasses.
2009 Jan 16 2:31 PM
Thanks Micky.
I found an ugly solution like this:
Here field itab1 will be tested.
DATA: abap_desc TYPE REF TO cl_abap_tabledescr,
is_data TYPE abap_bool,
is_reference type abap_bool.
TRY .
abap_desc ?= cl_abap_typedescr=>describe_by_data( itab1 ).
is_data = abap_desc->applies_to_data( itab1 ).
CATCH cx_root.
TRY .
abap_desc ?= cl_abap_typedescr=>describe_by_data_ref( itab1 ).
is_reference = abap_desc->APPLIES_TO_DATA_REF( itab1 ).
CATCH cx_root.
EXIT.
ENDTRY.
ENDTRY.Is there a more elegant way to do this?
Edited by: Dominik Deimling on Jan 16, 2009 3:32 PM
2009 Jan 16 3:04 PM
this was / is kind of what I had in mind as well. Not sure though if there is a more elegant way to do this using the classes mentioned. Unfortunately I do not have the time to figure this out.
But can't you just check the attributes of the CL_ABAP_TYPEDESCR to determine in one step the ABAP_TYPEKIND via instance attribute TYPE_KIND?
Just a suggestion not sure if this will work.
2009 Jan 29 1:57 PM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |