Hi Experts,
I have searched the solution in the forum, but unfortunately all the same problem still unsolved .
By refering to :
cl_abap_typedescr=>describe_by_data->length reports double length !
length of the field on the slection screen
and etc....
Please refer to my code:
-----------------------------------------------------------
data : it_tabdescr type abap_compdescr_tab,
wa_tabdescr type abap_compdescr.
data : ref_table_descr type ref to cl_abap_structdescr.
Data: lr_elem_descr TYPE REF TO cl_abap_elemdescr.
* Return structure of the table.
ref_table_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_tabdescr[] = ref_table_descr->components[].
loop at it_tabdescr into wa_tabdescr.
clear wa_fieldcat.
lr_elem_descr ?= cl_abap_elemdescr=>describe_by_data( wa_tabdescr-name ).
wa_fieldcat-intlen = lr_elem_descr->output_length.
wa_fieldcat-fieldname = wa_tabdescr-name .
wa_fieldcat-datatype = wa_tabdescr-type_kind.
wa_fieldcat-inttype = wa_tabdescr-type_kind.
* wa_fieldcat-intlen = wa_tabdescr-length.
wa_fieldcat-decimals = wa_tabdescr-decimals.
append wa_fieldcat to it_fieldcat.
endloop.
------------------------------------------------------
The question come up when after executed the class:-
ref_table_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_tabdescr[] = ref_table_descr->components[].
Then we get wrong field length -> all the length of it_tabdescr[].
The each field length normally is the double of the length of field in table in abap dictionary.
I am trying to get the correct field length by using
lr_elem_descr ?= cl_abap_elemdescr=>describe_by_data( wa_tabdescr-name ).
wa_fieldcat-intlen = lr_elem_descr->output_length.
But seem like it does not work.
Did any expert know why this problem happen and how to solve this?
Thanks in advance.