‎2008 Mar 06 7:24 AM
Hi all,
At runtime, I need to find out if a data-reference of created data
refers to a data-element or not.
In will give you an example of what I mean:
data: dummy TYPE bukrs,
descr_ref TYPE REF TO cl_abap_typedescr,
descr_datael TYPE REF TO cl_abap_elemdescr,
p_datael type string value ''.
descr_ref = cl_abap_typedescr=>describe_by_data( dummy ).
MOVE descr_ref ?TO descr_datael.
p_datael = descr_datael->help_id. "p_datael has now value BUKRS
How is this done, if we work with a datareferences?
I'm pretty sure it should be feasible - but I'm stuck here...
Task: same as above - find out data-element of dummy.
data: dummy TYPE ref to data,
descr_ref TYPE REF TO cl_abap_typedescr,
descr_datael TYPE REF TO cl_abap_elemdescr,
p_datael type string value ''.
create dummy type bukrs.
descr_ref = cl_abap_typedescr=>describe_by_data( dummy ).
"descr_ref->type_kind this time indicates, that we work with referenced data.
"How to progress from here on?
Thanks in advance. Points will be granted if issue can be solved!
‎2008 Mar 06 8:23 AM
Hello Edwin
The sample report ZUS_SDN_RTTI_DATA_ELEMENT shows how to address your question.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_RTTI_DATA_ELEMENT
*&
*&---------------------------------------------------------------------*
*& Thread: resolving data-reference at runtime ( cl_abap_typedescr)
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="770681"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_rtti_data_element.
DATA: gdo_dummy TYPE REF TO data,
go_typedescr TYPE REF TO cl_abap_typedescr,
go_elemdescr TYPE REF TO cl_abap_elemdescr,
p_datael TYPE string VALUE ''.
PARAMETERS:
p_rolln TYPE rollname DEFAULT 'BUKRS'.
START-OF-SELECTION.
CREATE DATA gdo_dummy TYPE (p_rolln).
go_typedescr = cl_abap_typedescr=>describe_by_data_ref( gdo_dummy ).
go_elemdescr ?= go_typedescr.
IF ( go_elemdescr->kind = cl_abap_elemdescr=>kind_elem AND
go_elemdescr->help_id = 'BUKRS' ).
MESSAGE 'Is of TYPE BUKRS' TYPE 'S'.
ELSE.
MESSAGE 'Is not of TYPE BUKRS' TYPE 'S'.
ENDIF.
END-OF-SELECTION.
Regards
Uwe
‎2008 Mar 06 8:23 AM
Hello Edwin
The sample report ZUS_SDN_RTTI_DATA_ELEMENT shows how to address your question.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_RTTI_DATA_ELEMENT
*&
*&---------------------------------------------------------------------*
*& Thread: resolving data-reference at runtime ( cl_abap_typedescr)
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="770681"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_rtti_data_element.
DATA: gdo_dummy TYPE REF TO data,
go_typedescr TYPE REF TO cl_abap_typedescr,
go_elemdescr TYPE REF TO cl_abap_elemdescr,
p_datael TYPE string VALUE ''.
PARAMETERS:
p_rolln TYPE rollname DEFAULT 'BUKRS'.
START-OF-SELECTION.
CREATE DATA gdo_dummy TYPE (p_rolln).
go_typedescr = cl_abap_typedescr=>describe_by_data_ref( gdo_dummy ).
go_elemdescr ?= go_typedescr.
IF ( go_elemdescr->kind = cl_abap_elemdescr=>kind_elem AND
go_elemdescr->help_id = 'BUKRS' ).
MESSAGE 'Is of TYPE BUKRS' TYPE 'S'.
ELSE.
MESSAGE 'Is not of TYPE BUKRS' TYPE 'S'.
ENDIF.
END-OF-SELECTION.
Regards
Uwe
‎2008 Mar 06 10:06 AM
‎2008 Mar 06 10:09 AM
Hello Edwin
Sometimes you do not see the wood for the trees...
Kind Regards
Uwe