Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to change ITAB created with CL_ABAP_TABLEDESCR from hashed to std

Former Member
0 Kudos

Hello xperts,

Ive created an ITAB (copy from another table) over the statements:

" Create instances of dynamic structure and dynamic internal table

go_sdescr_new = cl_abap_structdescr=>create( P_COMPONENTS = gt_components p_strict = abap_false ).

go_tdescr = cl_abap_tabledescr=>create( go_sdescr_new ).

" Create data refence followed by table creation

CREATE DATA gdo_handle TYPE HANDLE go_tdescr.

ASSIGN gdo_handle->* TO <gt_itab_BCCMP07>.

Unfortunately it is hashed and now I need to change it to a standard table, but cant figure out the syntax.

Any ideas?

3 REPLIES 3

naimesh_patel
Active Contributor
0 Kudos

I am not sure how did you created the dynamic table, but you can specify the type of table while generating the Dynamic Table type. Once you have assigned this table to field-symbol, you can just copy the data from your source table to this new table.


TYPES: BEGIN OF lty_data,
        bukrs TYPE t001-bukrs,
        bktxt TYPE bktxt,
       END   OF lty_data.

DATA: lt_data TYPE HASHED TABLE OF lty_data WITH UNIQUE DEFAULT KEY.
DATA: lwa_data LIKE LINE OF lt_data.
DO 5 TIMES.
  lwa_data-bukrs = '2000'.
  INSERT lwa_data INTO TABLE lt_data.
ENDDO.
DO 5 TIMES.
  lwa_data-bukrs = '1000'.
  INSERT lwa_data INTO TABLE lt_data.
ENDDO.

* Dynamic Table creation
DATA: lo_table   TYPE REF TO cl_abap_tabledescr,
      lo_struc   TYPE REF TO cl_abap_structdescr,
      lo_element  TYPE REF TO cl_abap_elemdescr,
      lo_new_type TYPE REF TO cl_abap_structdescr,
      lo_new_tab  TYPE REF TO cl_abap_tabledescr,
      lo_data     TYPE REF TO data,
      lt_comp     TYPE cl_abap_structdescr=>component_table.


* field symbols to access the dynamic table
FIELD-SYMBOLS: <f_tab>   TYPE ANY TABLE,
               <f_line>  TYPE ANY,
               <f_field> TYPE ANY.

* 1. Getting Compoents from existing type
lo_table ?= cl_abap_datadescr=>describe_by_data( lt_data ).
lo_struc ?= lo_table->get_table_line_type( ).
lt_comp  = lo_struc->get_components( ).

* 3. Create a New Type
lo_new_type = cl_abap_structdescr=>create( lt_comp ).
*
* 4. New Table type
lo_new_tab = cl_abap_tabledescr=>create(
                p_line_type  = lo_new_type
                p_table_kind = cl_abap_tabledescr=>tablekind_std   " <<
                p_unique     = abap_false ).
*
* 5. data to handle the new table type
CREATE DATA lo_data TYPE HANDLE lo_new_tab.
*
* 6. New internal table in the fieldsymbols
ASSIGN lo_data->* TO <f_tab>.

<f_tab> = lt_data.

Regards,

Naimesh Patel

0 Kudos

Thanks Naimesh but I want to change the table from Hashed to Standard type. You know how to accomplish that?

0 Kudos

How did you get GT_COMPONENTS?


go_sdescr_new = cl_abap_structdescr=>create( P_COMPONENTS = gt_components p_strict = abap_false ).

Regards,

Naimesh Patel