Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Using RTTI in table type any

Former Member
0 Likes
1,025

Hello,

i have table type any and i want to know in the loop for every field which type he have ,for instance for field type Date8.

what i the best way to do so , i guess that I need to use for instance cl_abap_elemdescr=>get_data_type_kind( <lv_field> ) but i dont know

how to use it and check every field in the loop ...

E.g.

loop at <lt_fields> assigning <ls_fields>

* check for every field in <ls_fields> which type he have and if the field is type date8 
* handle it diffrently


endloop.

Regards

Joy

1 ACCEPTED SOLUTION
Read only

former_member209703
Active Contributor
0 Likes
897

Can be something like this


data typedescr type ref to cl_abap_datadescr.
loop at <lt_fields> assigning <ls_fields>.
    typedescr ?= cl_abap_typedescr=>describe_by_data( <ls_fields> ).
    IF typedescr->type_kind = 'D'.
* * *
    ENDIF.
endloop.

6 REPLIES 6
Read only

former_member209703
Active Contributor
0 Likes
898

Can be something like this


data typedescr type ref to cl_abap_datadescr.
loop at <lt_fields> assigning <ls_fields>.
    typedescr ?= cl_abap_typedescr=>describe_by_data( <ls_fields> ).
    IF typedescr->type_kind = 'D'.
* * *
    ENDIF.
endloop.

Read only

0 Likes
897

HI Jose,

The issue here is that <ls_output> is structure and have more than multiple fields and can have

1 or more fields type D ....

Thanks and Regards

Joy

Read only

0 Likes
897

If <LS_OUTPUT> is an structure, then you can use something like this


data typedescr type ref to cl_abap_datadescr.
loop at <lt_fields> assigning <ls_output>.
 do.
   assign component sy-index of structure <ls_output> to <fs>.
   if sy-subrc eq 0.
    typedescr ?= cl_abap_typedescr=>describe_by_data( <ls_fields> ).
    IF typedescr->type_kind = 'D'.
    ENDIF.
  else.
    exit. 
  endif.
 enddo.
endloop.

Read only

0 Likes
897

Hi,

Just to clarify after small typing mistakes:


DATA typedescr TYPE REF TO cl_abap_datadescr.
FIELD-SYMBOLS <fs> TYPE ANY.

LOOP AT <lt_fields> ASSIGNING <ls_fields>.
 DO.
   ASSIGN COMPONENT sy-index OF STRUCTURE <ls_fields> TO <fs>.
   IF sy-subrc EQ 0.
     typedescr ?= cl_abap_typedescr=>describe_by_data( <fs> ).
     IF typedescr->type_kind = 'D'.
        "...
     ENDIF.
   ELSE.
    EXIT. 
   ENDIF.
 ENDDO.
ENDLOOP.

Kr,

m.

Read only

naimesh_patel
Active Contributor
0 Likes
897

You can use Absolute Name to get the absolute type from the type descriptor.


DATA: lt_vbak TYPE STANDARD TABLE OF vbak.

DATA: lo_struct   TYPE REF TO cl_abap_structdescr,
      lt_comp     TYPE cl_abap_structdescr=>component_table,
      la_comp     LIKE LINE OF lt_comp.

lo_struct ?= cl_abap_typedescr=>describe_by_name( 'VBAK' ).
lt_comp  = lo_struct->get_components( ).

WRITE: /(30) 'Field' , (40) 'Absolute Type'.

DATA: lv_abs_name TYPE string.
LOOP AT lt_comp INTO la_comp.
  WRITE: /(30) la_comp-name, (40) la_comp-type->absolute_name.
ENDLOOP.

Regards,

Naimesh Patel

Read only

0 Likes
897

HI Naimesh,

Sorry but I don't understand how i can use your code in my case,

the issue is that i have table type any and work area type any with multiple fields ...

Thanks,

Joy