3 Replies Latest reply: Oct 4, 2010 8:50 AM by Suhas Saha RSS

cl_abap_typedescr=>describe_by_name not returning correct length value

Bob Ackerman
Currently Being Moderated

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.

 

  • Re: cl_abap_typedescr=>describe_by_name not returning correct length value
    Uwe Schieferstein
    Currently Being Moderated

    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

Actions