on 09-18-2014 3:15 AM
Hi Experts,
I have searched the solution in the forum, but unfortunately all the same problem still unsolved .
By refering to :
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Leong!
I mean ABAP TYPE p
My code (in your variables) was like that:
But it's just a "code on a napkin" for a single run, please test it carefully. I didn't have i and f components in a table, check their representation if necessary.
LOOP at it_tabdescr into wa_tabdescr.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = wa_tabdescr-name .
wa_fieldcat-datatype = wa_tabdescr-type_kind.
wa_fieldcat-inttype = wa_tabdescr-type_kind.
IF wa_tabdescr-type_kind <> 'P'.
wa_fieldcat-intlen = wa_tabdescr-length / 2.
ELSE.
wa_fieldcat-intlen = wa_tabdescr-length * 2 - 1.
ENDIF.
wa_fieldcat-decimals = wa_tabdescr-decimals.
APPEND wa_fieldcat TO lt_fieldcat.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcat
IMPORTING
ep_table = lt_my_table.
ASSIGN lt_my_table->* TO <fs_my_table>.
Hi,
When using a Unicode system, each CHAR is in UTF-16 format i.e each CHAR takes 2 bytes of data.
So for a character type object like 'ABCDE', the 5 characters are stored internally in 5 * 2 Bytes = 10 Bytes.
The length which you are getting from the method is calculated using system kernel's method and not in ABAP. As the system is only aware of the internal length of the object so it returns the same and you get twice the size which you see on your screen.
Regards,
Ashish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
LENGTH in CL_ABAP_TYPEDESCR is the internal length. If you are on a unicode system, this mostly should be the double value of the output length.
Regards,
Klaus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
102 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.