CL_ABAP_TYPEDESCR

If I create a user defined type with reference to a DDIC object I can obtain the list of fields in the user defined type and the obsolute name which contains the user defined type by calling method describe_by_data of class cl_abap_structdescr at run time.
Does anyone know how you can find the original ddic structure at runtime of the type TY_POHEADER.
TYPES: ty_poheader TYPE bapimepoheader.
DATA: dref TYPE REF TO data.
DATA: descr_ref TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS: <fs_line2> TYPE ty_poheader.
Start-of-selection.
CREATE DATA dref TYPE ty_poheader.
ASSIGN dref->* TO <fs_line2>.
descr_ref ?= cl_abap_typedescr=>describe_by_data( <fs_line2> ).

i am getting all the components of the original ddic structure. check out the program below.
REPORT  zzorgdataget                            .
TYPES: ty_poheader TYPE bapimepoheader.
DATA: dref TYPE REF TO data.
DATA: descr_ref1 TYPE REF TO cl_abap_structdescr.
DATA : l_string TYPE string.
DATA : l_object TYPE dd_x031l_table.
DATA : l_true TYPE abap_bool.
DATA : l_desc TYPE REF TO cl_abap_typedescr.
FIELD-SYMBOLS: <fs_line2> TYPE ty_poheader.
START-OF-SELECTION.
  TYPES: my_struct TYPE mepoheader.
  DATA:
    my_data   TYPE my_struct,
    descr_ref TYPE REF TO cl_abap_structdescr.
  FIELD-SYMBOLS:
    <comp_wa> TYPE abap_compdescr.
START-OF-SELECTION.
  descr_ref ?= cl_abap_typedescr=>describe_by_data( my_data ).
  WRITE: / 'Typename     :', descr_ref->absolute_name.
  WRITE: / 'Kind         :', descr_ref->type_kind.
  WRITE: / 'Length       :', descr_ref->length.
  WRITE: / 'Decimals     :', descr_ref->decimals.
  WRITE: / 'Struct Kind  :', descr_ref->struct_kind.
  WRITE: / 'Components'.
  WRITE: / 'Name              Kind   Length   Decimals'.
  LOOP AT descr_ref->components ASSIGNING <comp_wa>.
    WRITE: / <comp_wa>-name, <comp_wa>-type_kind,
             <comp_wa>-length, <comp_wa>-decimals.
  ENDLOOP.

Similar Messages

  • CL_ABAP_TYPEDESCR does not return integer or decimal field

    Dear All,
    I have an internal table for which I want to get dynamically list of fields.
    I use class CL_ABAP_TYPEDESCR and method DESCRIBE_BY_DATA.
    The list of field is then placed in table CL_ABAP_TYPEDESCR->KEY. The problem
    is that fields with integer type (FIELD FACTOR) are not listed there. What do I do wrong?
    TYPES: BEGIN OF t_table,
            name(20)   TYPE C,
            period(10) TYPE C,
            factor     TYPE I,
          END OF t_table.
    DATA: it_table TYPE STANDARD TABLE OF t_table.
    DATA: wa_table TYPE t_table.
    wa_table-name = 'Brown'. wa_table-period = '2010'. wa_table-factor = 100. APPEND wa_table TO it_table.
    wa_table-name = 'Brown'. wa_table-period = '2011'. wa_table-factor = 200. APPEND wa_table TO it_table.
    wa_table-name = 'Fox'.   wa_table-period = '2010'. wa_table-factor = 50.  APPEND wa_table TO it_table.
    wa_table-name = 'Fox'.   wa_table-period = '2010'. wa_table-factor = 900. APPEND wa_table TO it_table.
    TYPE-POOLS: ABAP.
    DATA: L_REF TYPE REF TO CL_ABAP_TABLEDESCR.
    l_ref ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( it_table ).
    * TABLE l_ref->key DOES NOT SHOW FIELD "FACTOR" (TYPE I)....
    FIELD-SYMBOLS: <KEY_COMP_WA> TYPE ABAP_KEYDESCR.
    LOOP AT l_ref->key ASSIGNING <KEY_COMP_WA>.
       WRITE:/ <KEY_COMP_WA>-NAME.
    ENDLOOP.
    Best regards,
    Mark

    Hi Mark,
    if you want the fields you should consider attribute components, compare this snippet getting the field names of any structure or table (from the times when I still used FORM routines)
    FORM getfields
      USING    px_data                        TYPE any
      CHANGING pt_fields                      TYPE table.
      DATA:
        lt_comp                               TYPE abap_compdescr_tab,
        lr_dat                                TYPE REF TO data,
    **    lv_kind                             TYPE abap_typecategory,
        lr_typedescr                          TYPE REF TO cl_abap_typedescr,
    **    lr_tabledescr                       TYPE REF TO cl_abap_tabledescr,
        lr_structdescr                        TYPE REF TO cl_abap_structdescr.
      FIELD-SYMBOLS:
        <fs>                                  TYPE ANY,
        <ft>                                  TYPE ANY TABLE,
        <comp>                                TYPE LINE OF abap_compdescr_tab.
      lr_typedescr ?= cl_abap_typedescr=>describe_by_data( px_data ).
      CASE lr_typedescr->kind.
        WHEN 'S'.
          lr_structdescr ?= lr_typedescr.
          lt_comp                             = lr_structdescr->components.
        WHEN 'T'.
          ASSIGN px_data TO <ft>.
          CREATE DATA lr_dat                  LIKE LINE OF <ft>.
          ASSIGN lr_dat->* TO <fs>.
          lr_structdescr ?= cl_abap_structdescr=>describe_by_data( <fs> ).
          lt_comp                             = lr_structdescr->components.
        WHEN OTHERS.
          MESSAGE e241(00).
    *   Function is invalid in this environment
      ENDCASE.
      CLEAR pt_fields.
      LOOP AT lt_comp ASSIGNING <comp>.
        APPEND <comp>-name TO pt_fields.
      ENDLOOP." at lt_comp assigning <comp>.
    ENDFORM.                    " getfields
    Regards,
    Clemens

  • Dynamic programming using cl_abap_typedescr

    I have created a field catalog for an ALV grid dynamically using cl_alv_table_create=>create_dynamic_table (I am on 46B and cannot use the new version).  How do I create the structure and therefore internal table to pass into the it_outtab parameter of the ALV grid set_table_for_first_display
    method?  I can create a blank table with the correct dynamic columns but now wish to populate it without much success!  I am retrieving the type using cl_abap_typedescr=>describe_by_data and can cycle through the key but how do I just obtain the structure?
    Cheers
    Ian
    cl_abap_typedescr to retrieve the column names of a dynamic table I have created for using with an ALV grid

    Hi,
    Use ASSIGN r_dyn_table->* TO <t_dyn_table> to get access to the dynamic table. To append rows to it, you should use ASSIGN COMPONENT idx/name OF STRUCTURE struc TO <fs>.
    Example:
        data: tab_fields like table of wa_fields,
             r_dyn_table  TYPE REF TO data,
             r_wa_dyn_table   TYPE REF TO data,
             f_int type i.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
          EXPORTING
            it_fieldcatalog           = F_TAB_FCAT
          IMPORTING
            ep_table                  = r_dyn_table
          EXCEPTIONS
            generate_subpool_dir_full = 1
            OTHERS                    = 2.
          ASSIGN r_dyn_table->* TO <t_dyn_table>.
          CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.
          ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.
          DESCRIBE TABLE tab_fields lines f_int.
          do f_int times.
            READ TABLE tab_fields INDEX sy-index into wa_fields.
            ASSIGN wa_fields-field TO <w_field1>.
            check1 = sy-subrc.
            ASSIGN COMPONENT sy-index
                   OF STRUCTURE <wa_dyn_table> TO <w_field2>.
            check2 = sy-subrc.
            if check1 = 0 and check2 = 0.
              <w_field2> = <w_field1>.
            endif.
          enddo.
    Svetlin

  • Class CL_ABAP_TYPEDESCR's method DESCRIBE_BY_DATA

    Hello!
    How can I call CL_ABAP_TYPEDESCR's Method DESCRIBE_BY_DATA
    with the CALL command ?
    Many thanks in advance for your kindly efforts.
    Reagards
    Ilhan

    Hi Ilhan,
    In the abap editor, place the cursor where you want to put the CALL.
    1->click the "Pattern" button (CTRL F6)
    2->choose the radio button "ABAP Object patterns", Click Enter
    3->in then next popup, choose the first radio button "Call Method"
    4->Enter "CL_ABAP_TYPEDESCR" in the class name field
    5->Enter "DESCRIBE_BY_DATA" in the method field, click Enter
    you have the pattern in the editor
    OR
    you may copy the following code, and pass the parameters
    data: l_describe TYPE REF TO cl_abap_typedescr.
    field-symbols: <field>.
    data: field_name(15).
    ASSIGN TABLE FIELD (field_name) TO <field>
    call method cl_abap_typedescr=>describe_by_data
      exporting
        p_data      = <field>
      receiving
        p_descr_ref = l_describe
    Or Simply
      ASSIGN TABLE FIELD (field_name) TO <field>.                 
    l_describe = cl_abap_typedescr=>describe_by_data( <field> ).
    Hope this helps,
    Sajan Joseph.

  • Serialize CL_ABAP_TYPEDESCR

    I want to serialize data (using CALL TRANSFORMATION or EXPORT TO DATABASE) of an unknown (maybe complex) type (passed as ANY parameter to a method), and then later deserialize it in another program. To do this I need to dynamically create a variable of the original type, but for instance I cannot serialize the necessary CL_ABAP_TYPEDESCR along with the serialized data, because it does not contain the interface IF_SERIALIZABLE_OBJECT.
    So, what I'm looking for is a way to get the type of a variable, store it, and then dynamically create a variable of this type. Any ideas?

    Okay, I recently made some progress: I've created wrapper classes for some of the ABAP RTTS classes and currently it seems like I'm able to de-/serialize all data/table/structure/object types defined in the dictionary plus most structure/table types defined in ABAP. Unless someone is interested in details, or has a better idea, the problem is solved for me.

  • Cl_abap_typedescr= describe_by_data( gt_table )

    Afternoon all
    I am using cl_abap_typedescr=>describe_by_data( <gt_table> ) to retrieve the fieldlist of my dynamically created ALV fieldcatalog.  However, I have just switched to using some fields that are of type INT and now the method ignores them.  Is this correct???  Is there another method that I should be using?  I am on 46B.
    Cheers
    Ian

    Here is a sample program which has 10 INT4 fields, works good for me.
    report zrich_0002
           no standard page heading.
    type-pools: slis.
    type-pools: abap.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: alv_fldcat type slis_t_fieldcat_alv,
          it_fldcat type lvc_t_fcat.
    selection-screen begin of block b1 with frame title text-001.
    parameters: p_check type c.
    selection-screen end of block b1.
    start-of-selection.
      perform build_dyn_itab.
      perform build_report.
      data : it_details type abap_compdescr_tab.
      data : ref_descr type ref to cl_abap_structdescr.
      ref_descr ?= cl_abap_typedescr=>describe_by_data( <dyn_wa> ).
      it_details[] = ref_descr->components[].
    * Write out data from table.
      loop at <dyn_table> into <dyn_wa>.
        do.
          assign component  sy-index  of structure <dyn_wa> to <dyn_field>.
          if sy-subrc <> 0.
            exit.
          endif.
          if sy-index = 1.
            write:/ <dyn_field>.
          else.
            write: <dyn_field>.
          endif.
        enddo.
      endloop.
    *  Build_dyn_itab
    form build_dyn_itab.
      data: index(3) type c.
      data: new_table type ref to data,
            new_line  type ref to data,
            wa_it_fldcat type lvc_s_fcat.
    * Create fields
      clear index.
      do 10 times.
        index = sy-index.
        clear wa_it_fldcat.
        concatenate 'Field' index into
                 wa_it_fldcat-fieldname .
        condense  wa_it_fldcat-fieldname no-gaps.
        wa_it_fldcat-datatype = 'INT4'.
        wa_it_fldcat-intlen = 5.
        append wa_it_fldcat to it_fldcat .
      enddo.
    * Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = it_fldcat
                   importing
                      ep_table        = new_table.
      assign new_table->* to <dyn_table>.
    * Create dynamic work area and assign to FS
      create data new_line like line of <dyn_table>.
      assign new_line->* to <dyn_wa>.
    endform.
    *      Form  build_report
    form build_report.
      data: fieldname(20) type c.
      data: fieldvalue(5) type c.
      data: index(3) type c.
      field-symbols: <fs1>.
      do 10 times.
        index = sy-index.
    * Set up fieldname
        concatenate 'FIELD' index into
                 fieldname .
        condense   fieldname  no-gaps.
    * Set up fieldvalue
        fieldvalue = index.
        condense   fieldvalue no-gaps.
        assign component  fieldname  of structure <dyn_wa> to <fs1>.
        <fs1> =  fieldvalue.
      enddo.
    * Append to the dynamic internal table
      append <dyn_wa> to <dyn_table>.
    endform.
    Regards,
    Rich Heilman

  • Cl_abap_typedescr= describe_by_name not returning correct length value

    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.

    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

  • Dynamic types with CL_ABAP_TYPEDESCR

    Hi,
    I have a problem. I want to read out the output_length of dynamic types to evaluate inputs. I do something like the code below.
    DATA type_ref      TYPE REF TO cl_abap_typedescr.
    DATA elem_descr TYPE REF TO cl_abap_elemdescr.
    DATA struc_descr TYPE REF TO cl_abap_structdescr.
    type_ref = cl_abap_typedescr=>describe_by_data( <fs_lsinto> ).
    elem_descr ?= type_ref.
    elem_descr->output_length
    But sometimes type_ref give back a CL_ABAP_STRUCTDESCR and I get a dump at '?='.
    How I can solve my Problem?
    Sinan

    How about something like this.
    report  zrich_0001.
    data type_ref type ref to cl_abap_typedescr.
    data elem_descr type ref to cl_abap_elemdescr.
    data struc_descr type ref to cl_abap_structdescr.
    data comp_tab type abap_compdescr_tab.
    data comp_wa like line of comp_tab.
    parameters: p_name(30) type c.
    type_ref = cl_abap_typedescr=>describe_by_name( p_name ).
    if type_ref->type_kind = 'u'.            " <- Structure
      struc_descr ?= type_ref.
      loop at struc_descr->components into comp_wa.
        catch system-exceptions move_cast_error = 1.
          data: tab_component type string.
         concatenate p_name comp_wa-name into comp_wa-name separated by '-'.
          elem_descr ?= cl_abap_typedescr=>describe_by_name( comp_wa-name ).
        endcatch.
        write:/ comp_wa-name, comp_wa-length, elem_descr->output_length.
      endloop.
    else.
      elem_descr ?= type_ref.
      write:/ p_name, elem_descr->output_length.
    endif.
    Regards,
    Rich Heilman

  • L_descr_ref ?=cl_abap_typedescr= describe_by_data( gt_tab ).

    Hi,
    I have written the code as follows to get the components of the file uploaded.But it goes for dump at the statement written at subject line: And it says " However, the current content of the source variable does not fit into
    the target variable." please help!!!
    TYPES: BEGIN OF ttab_type,
             rec(1000) TYPE c,
           END OF ttab_type.
      DATA:gt_tab  TYPE TABLE OF ttab_type.
      DATA: l_descr_ref       TYPE REF TO cl_abap_structdescr,
             g_line TYPE string,
             gt_field                 TYPE crmt_mktimex_field_tab.
    DATA: lt_table TYPE REF TO data,
          lt_line  TYPE REF TO data,
          ls_xfc TYPE lvc_s_fcat,
          ls_ifc TYPE lvc_t_fcat,
          lt_details TYPE abap_compdescr_tab,
          lw_details TYPE abap_compdescr.
      FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                   <dyn_wa>,
                   <dyn_field>.
    CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                = pfile1
          filetype                = 'ASC'
          has_field_separator     = 'X'
        TABLES
          data_tab                = gt_tab
        EXCEPTIONS
          file_open_error         = 1
          file_read_error         = 2
          no_batch                = 3
          gui_refuse_filetransfer = 4
          invalid_type            = 5
          no_authority            = 6
          unknown_error           = 7
          bad_data_format         = 8
          header_not_allowed      = 9
          separator_not_allowed   = 10
          header_too_long         = 11
          unknown_dp_error        = 12
          access_denied           = 13
          dp_out_of_memory        = 14
          disk_full               = 15
          dp_timeout              = 16
          OTHERS                  = 17.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
        l_descr_ref ?=
          cl_abap_typedescr=>describe_by_data( gt_tab ).
          lt_details[] = l_descr_ref->components[].
    Edited by: Ginger on Jul 3, 2009 1:18 AM

    Ya...as rightly said by Vamsi...
    change your declaration as
    l_descr_ref  TYPE REF TO cl_abap_tabledescr,
    It will work....and for your information you can also use the below codes for getting components..
    DATA:  lv_ref_table        TYPE REF TO cl_abap_tabledescr,
           lv_ref_struct       TYPE REF TO cl_abap_structdescr,
      lv_ref_table  ?= cl_abap_tabledescr=>describe_by_data( et_data ).
      lv_ref_struct ?= lv_ref_table->get_table_line_type( ).
      lt_details[]   = lv_ref_struct->components.

  • CL_ABAP_TYPEDESCR - DESCRIBE_BY_DATA  field length is doubled

    I have a custom program developed on Non Unicode system, that is using CL_ABAP_TYPEDESCR -> DESCRIBE_BY_DATA  to get field lengths of the fields in a structure. The code works perfectly file on Non Unicode system where it is developed, However when the same code is imported on a UNICODE system the field lengths of the fields in the same structure are exactly doubled. Anybody has any idea, why this may be happening?

    > However when the same code is imported on a UNICODE system the field lengths of the fields in the same structure are exactly doubled. Anybody has any idea, why this may be happening?
    Yes - because Unicode uses two bytes to represent ONE character.
    Markus

  • Using CL_ABAP_TYPEDESCR for local itabs?

    Can I get the component table of a locally defined internal table using cl_abap runtime class/methods?

    Of course...
    This is from class documentation available for class CL_ABAP_TABLEDESCR
    REPORT typedescr_test.
    TYPES:
      my_table TYPE HASHED TABLE OF i WITH UNIQUE KEY TABLE LINE.
    DATA:
      descr_ref TYPE ref to cl_abap_tabledescr.
    FIELD-SYMBOLS:
      <key_comp_wa> TYPE abap_keydescr.
    START-OF-SELECTION.
      descr_ref ?= cl_abap_typedescr=>describe_by_name( 'MY_TABLE' ).
      WRITE: / 'Typename      :', descr_ref->absolute_name.
      WRITE: / 'Kind          :', descr_ref->type_kind.
      WRITE: / 'Length        :', descr_ref->length.
      WRITE: / 'Decimals      :', descr_ref->decimals.
      WRITE: / 'Table Kind    :', descr_ref->table_kind.
      WRITE: / 'Initial Size  :', descr_ref->initial_size.
      WRITE: / 'Key Def Kind  :', descr_ref->key_defkind.
      WRITE: / 'Has Unique Key:', descr_ref->has_unique_key.
      WRITE: / 'Key Components:'.
      LOOP AT descr_ref->key ASSIGNING <key_comp_wa>.
        WRITE <key_comp_wa>-name.
      ENDLOOP.
    Regards,
    Abhijit

  • Append new field after call cl_abap_typedescr= describe_by_name( tabname )

    Dears :
      i use cl_abap_typedescr=>describe_by_name( tabname ) to create a new structure type. The parameter tabname could be 'MARA' .
      and now i want to append a new field such as 'ZTEST' to this structure, is this possible ?
      ths in advance!

    Hi,
      This is possible, Use get_components method to get the list of components
    Then once yout get this list add one more component to this list.
    Then use this list to create your strucutre using the method create.
    See the below code.
    DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.
    DATA: lt_comp       TYPE cl_abap_structdescr=>component_table.
    DATA: ls_comp       LIKE LINE OF lt_comp.
        lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
        lt_comp = lr_rtti_struc->get_components( ).
        LOOP AT it_elements INTO wa_element.
          ls_comp-name = wa_element.
          ls_comp-type = cl_abap_elemdescr=>get_string( ).
          APPEND ls_comp TO lt_comp.
        ENDLOOP.
        CALL METHOD cl_abap_structdescr=>create
          EXPORTING
            p_components = lt_comp
            p_strict     = abap_false
          RECEIVING
            p_result     = lr_rtti_struc.
    Regards,
    Sesh
    Message was edited by:
            Seshatalpasai Madala

  • Dump at cl_abap_typedescr= describe_by_data

    Hi ,
    My code is as follows:
      l_descr_ref ?= cl_abap_typedescr=>describe_by_data( gt_fldname ).
      BREAK-POINT.
      CLEAR : l_counter.
      LOOP AT l_descr_ref->components[] ASSIGNING <lfs_comp_wa>.
        l_counter = l_counter + 1.
        ASSIGN COMPONENT l_counter OF STRUCTURE gt_fldname TO <lfs_comp>.
        <lfs_comp> = <lfs_comp_wa>-name.
      ENDLOOP.
    But it goes for dump at   l_descr_ref ?= cl_abap_typedescr=>describe_by_data( gt_fldname ).Can anyone tell why?

    Hi My code is as follows:
      DATA : l_descr_ref TYPE REF TO cl_abap_structdescr,
             l_counter TYPE sytabix.
      FIELD-SYMBOLS:
             <lfs_comp_wa> TYPE abap_compdescr,
             <lfs_comp>     TYPE ANY.
      l_descr_ref ?= cl_abap_typedescr=>describe_by_data( gt_fldname ).
      CLEAR : l_counter.
      LOOP AT l_descr_ref->components[] ASSIGNING <lfs_comp_wa>.
        l_counter = l_counter + 1.
        ASSIGN COMPONENT l_counter OF STRUCTURE gt_fldname TO <lfs_comp>.
        <lfs_comp> = <lfs_comp_wa>-name.
      ENDLOOP.
    And if I change the type, then it says there is no components[].
    Edited by: Jjammy on Jul 14, 2009 3:24 PM

  • Problem about CL_ABAP_TYPEDESCR

    Hi Buddies,
       There was a strange problem which I encountered today.When I called the method cl_abap_typedescr=>describe_by_data to obtain the components of the table DD01T, the length of each component of this table was doubled.After I used this components table to create an internal table dynamically, the problem is occured due to doule length of the true lengh..
    Suddently I realized that the problem was caused by UNICODE.Did anyone has the idea to get the right length?
    DATA: structtype TYPE REF TO cl_abap_structdescr.
    structtype ?= cl_abap_typedescr=>describe_by_data( u2018DD01Tu2019 ).

    Hello,
    I used POSID instead of PSPNR.
    Regards,
    Pedro

  • Ref_descr ?= cl_abap_typedescr= describe_by_name explanation

    Hello Everyone,
    Can somebody explain what is happening
    in this part of the code. Below the complete code.
    ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
      it_details[] = ref_descr->components[].
    One more request, what are these structures
    abap_compdescr_tab, abap_compdescr, cl_abap_structdescr, lvc_s_fcat are these tables? Please kindly let me know
    data : it_details type abap_compdescr_tab,
           wa_details type abap_compdescr.
    data : ref_descr type ref to cl_abap_structdescr.
    data:  new_table type ref to data,
           new_line  type ref to data,
           wa_it_fldcat type lvc_s_fcat.
    ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
      it_details[] = ref_descr->components[].
      loop at it_details into wa_details.
        clear wa_it_fldcat.
        if wa_details-name = 'TIMESTMP'.
          wa_it_fldcat-fieldname = wa_details-name.
          wa_it_fldcat-datatype = wa_details-type_kind.
          wa_it_fldcat-inttype = wa_details-type_kind.
          wa_it_fldcat-intlen = r.
          wa_it_fldcat-decimals = wa_details-decimals.
          append wa_it_fldcat to it_fldcat.
          append wa_it_fldcat-fieldname to it1.
            else.
          wa_it_fldcat-fieldname = wa_details-name.
          wa_it_fldcat-datatype = wa_details-type_kind.
          wa_it_fldcat-inttype = wa_details-type_kind.
          wa_it_fldcat-intlen = wa_details-length.
          wa_it_fldcat-decimals = wa_details-decimals.
          append wa_it_fldcat to it_fldcat.
          append wa_it_fldcat-fieldname  to it1.
        endif.
      endloop.
    Thanks
    Krishna

    Hello Krishna
    The static method cl_abap_typedescr=>describe_by_name returns an instance of type CL_ABAP_TYPEDESCR.
    This class is a superclass of CL_ABAP_STRUCTDESCR (the inheritance hierarchy is:
    CL_ABAP_TYPEDESCR -> CL_ABAP_DATADESCR -> CL_ABAP_COMPLEXDESCR -> CL_ABAP_STRUCTDESCR).
    In the statement
    ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
    it_details[] = ref_descr->components[].
    we have a widening cast ('?=') from CL_ABAP_TYPEDESCR (returned value) to CL_ABAP_STRUCTDESCR (descr_ref variable).
    Now <i>p_table</i> represents a structure (like 'SFLIGHT'). The components of this structure, i.e. the table fields, are found in the public attribute ref_descr->components.
    Please note that it is unnecessary to write
    ref_descr->components<b>[]</b>
    because in ABAP-OO it is not allowed to use itabs with header lines but exclusively table types.
    The other classes (like cl_abap_typedescr, cl_abap_compdescr) are used to get the runtime type information (RTTI) of different DDIC objects.
    Regards
      Uwe

Maybe you are looking for