‎2011 Oct 02 7:05 PM
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
‎2011 Oct 02 7:26 PM
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.
‎2011 Oct 02 7:26 PM
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.
‎2011 Oct 02 7:32 PM
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
‎2011 Oct 02 7:44 PM
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.
‎2011 Oct 02 9:28 PM
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.
‎2011 Oct 02 7:35 PM
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
‎2011 Oct 02 7:40 PM
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