cancel
Showing results for 
Search instead for 
Did you mean: 

From generic CL_WD_UIELEMENT to datatype

matteo_montalto
Contributor
0 Kudos

Hi all gurus,

need help on this simple task.

In a WDDOMODIFYVIEW routine, I'm looping over some customer fields which are - specifically - inputfields, checkboxes, and so on... Generically, on each loop pass, a field is processed and the reference is stored into a generic typeref to CL_WD_UIELEMENT object.

Now; I want to perform a specific action only for those fields which are DATS(8).

In order to do this, I should find a way that, given a CL_WD_UIELEMENT data reference, returns me the "inner" data type of the field.

This means that if I define a data element which is simply a DATS renamed, I should be able to recognize it as DATS.

Is there any facility to do this?

So far I noticed that  cl_abap_typedescr=>describe_by_data( ) could be what I'm looking for... but I'm not dealing with a datastructure; I'm looping over CL_WD_UIELEMENT references.

Any help will be appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

former_member184578
Active Contributor
0 Kudos

Hi,

There won't be any type for the UI elements. You actually have to get the binding ( attribute ) of the UI element and then use cl_abap_typedescr=>describe_by_data( ) to get the data type.

Or, While looping over CL_WD_UIELEMENT references, use the method GET__PRIMARY_PROPERTY_TYPE to get the RTTI type from which you can get the data type.

Sample Code:


DATA: lt_child             TYPE cl_wd_uielement=>tt_uielement.

DATA lr_type                TYPE REF TO CL_ABAP_TYPEDESCR.

FIELD-SYMBOLS: <lr_uielement> TYPE REF TO cl_wd_uielement.


LOOP AT lt_child ASSIGNING <lr_uielement>.

*    Get type associated to the UI element

     lr_type ?= <lr_uielement>->GET__PRIMARY_PROPERTY_TYPE( ).

     IF lr_type IS BOUND.

*      " Then access the following attributes

      lr_type->absolute_name  "   will contain the Data element


      lr_type->type_kind  " will contain the actual Data type

    

      lr_type->length  " will contain the length

     ENDIF.


......


ENDLOOP.


  .

Hope this helps u,

Regards,

Kiran

matteo_montalto
Contributor
0 Kudos

Hi Kiran,

your support is precious, as always
I managed to do it via DDIF_FIELDINFO_GET but I like you solution more; there's just one thing I'd like to clarify.

While on the DDIF_FIELDINFO_GET solution I read the entry for the corresponding field name and checked for:

DATATYPE  = 'DATS'

and LENG    = '000008'

as these values characterize a sy-datum like custom fields for me.

Actually, looking at your solution, I should work on:

lr_type->type_kind = 'D'

but ... lr_type->length gives me 16 for these fields (intending probably "internal length").

I noticed that lr_type has an instance attribute called DFIES_CACHE (it's an hashed table), which contains all the data I'd like to check. Unfortunately, DFIES_CACHE is a private attribute and I didn't find any method to retrieve data from it.


Could you please help on this task?

EDIT: Found it:

DATA: le_type                 TYPE REF TO CL_ABAP_ELEMDESCR,

          ls_dfies                TYPE dfies.

...        

         clear ls_dfies.

         le_type ?= lr_type.

         CALL METHOD le_type->get_ddic_field

*          EXPORTING

*            p_langu      = SY-LANGU

           RECEIVING

             p_flddescr   = ls_dfies

*          EXCEPTIONS

*            not_found    = 1

*            no_ddic_type = 2

*            others       = 3

                 .

         IF  ls_dfies-datatype EQ 'DATS' AND ls_dfies-LENG EQ '8'.

* my code.


Thanks

Answers (0)