09-30-2010 8:58 PM
Hi,
I am using cl_abap_typedescr=>describe_by_name to get the length and field names of a table. But it is returning incorrect values for length. For example, all character fields and numc fields contain double the correct length
REPORT ZCA_BOB_CL_ABAP_STRUCTDESCR.
PARAMETERS P_TABNAM type TABNAME OBLIGATORY.
Data: wa_spfli type spfli,
r_descr type REF TO cl_abap_structdescr,
wa_comp TYPE abap_compdescr.
** Create references to the needed ALV Global Classes
data: lr_events type ref to cl_salv_events_table.
data: gr_table type ref to cl_salv_table.
Data: r_grid TYPE REF TO cl_salv_table.
data: r_title_text TYPE REF TO cl_alv_variant,
r_grid_title TYPE LVC_TITLE.
Data: abap_compdescr_tab TYPE STANDARD TABLE OF abap_compdescr
WITH KEY name.
START-OF-SELECTION.
** ?= means cast
** r_descr ?= cl_abap_typedescr=>describe_by_data( wa_spfli ).
r_descr ?= cl_abap_typedescr=>describe_by_name( P_TABNAM ).
Loop at r_descr->components into wa_comp.
* write:/ wa_comp-name, wa_comp-type_kind, wa_comp-length,
* wa_comp-decimals.
append wa_comp to abap_compdescr_tab.
EndLoop.
09-30-2010 9:47 PM
Hello Bob
Below is the output of your report run on a 4.6c system:
Structure WA_SPFLI:
MANDT C 3 0
CARRID C 3 0
CONNID N 4 0
COUNTRYFR C 3 0
CITYFROM C 20 0
AIRPFROM C 3 0
COUNTRYTO C 3 0
CITYTO C 20 0
AIRPTO C 3 0
FLTIME I 4 0
DEPTIME T 6 0
ARRTIME T 6 0
DISTANCE P 5 4
DISTID C 3 0
FLTYPE C 1 0
PERIOD b 1 0
4.6c = non-Unicode
Your system = Unicode
Thus, the length is apprently the length in bytes.
Simply check and RFC destination (SM59) using button "Unicode Test". You will get the following message on an Unicode system:
Target is a unicode system (character size 2)
Regards
Uwe
10-01-2010 8:16 PM
Yes, we are on a unicode system. Hard to understand why this would act different on a unicode vs. non-unicode system. I tried testing it thru SE24 and the it has the problem there as well. Any suggestions?
10-04-2010 7:50 AM
Hello Bob,
I remember a couple of forum discussions on the same problem. The length value returned by SAP is in bytes & not in characters.
Unfortunately i am not able to locate them I remember Sandra Rossi being involved in the thread!
BR,
Suhas