Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

cl_abap_typedescr=>describe_by_data - get wrong field length

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.

Tags:
Former Member
Former Member replied

Hi, Leong!

Yes, it's because of unicode support enabled in your system.

Recently I urgently needed to create an internal table with a structure like "some Z structure several months ago" and here are the "magic numbers" (not so magic in fact ) to get the field lengths:

for character-like fields you need half of the output_length, for packed objects it'll be 2 * output_length - 1.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question