Application Development and Automation 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: 
Read only

Dynamic table type

Former Member
0 Likes
672

Hi folks,

Is there any generic data type for table declaration, beside :

 data: lt_generic type table of data  

I know that field-symbols can have the generic table type any

 field-symbols: <lft_generic> type any table.  

I basically want to be able to read from generic tables.

 READ TABLE lt_generic ....  

Thanks

Andreas

5 REPLIES 5
Read only

Former Member
0 Likes
634

Andreas,

I think you are going to have to throw a bit more info into the ring so a better assessment of your requirement can be made.

Cheers,

Neil.

Read only

0 Likes
634

Hi Neil,

actually i want to execute a read on the dynamic created tabel.

Maybe this repot explains my purpose.

 REPORT  ztc_dqm_dynamic.

************************************************************************
* Step 1: << local definitions >>
************************************************************************

" << variables >>

" << error string >>
DATA: lv_error TYPE string.

" --------------------------------------------------------------------- "

" << struc >>

" << holds one component >>
DATA: ls_component TYPE
      cl_abap_structdescr=>component.

" --------------------------------------------------------------------- "

" << table >>

DATA: lt_component TYPE cl_abap_structdescr=>component_table.

DATA: lt_db_indexfields TYPE TABLE OF ztcc_dqm_indices.

" --------------------------------------------------------------------- "

" << dynamic >>

" << generated struc >>
DATA: ls_dystruc TYPE REF TO data.

" << generated table >>
DATA: lt_dytable TYPE REF TO data.

" --------------------------------------------------------------------- "

" << field symbols >>

FIELD-SYMBOLS: <lfs_indexfields> TYPE ANY TABLE.

FIELD-SYMBOLS: <lfs_indexfield> TYPE ANY.

FIELD-SYMBOLS: <lfs_db_indexfields> TYPE ztcc_dqm_indices.

" --------------------------------------------------------------------- "

" << objects >>

DATA: lr_struc_type TYPE REF TO cl_abap_structdescr.

DATA: lr_table_type TYPE REF TO cl_abap_tabledescr.


" --------------------------------------------------------------------- "

" << exception >>

DATA: lr_ex TYPE REF TO cx_sy_type_creation.


************************************************************************
* Step 2: << dynamic struc >>
************************************************************************

" << set struc fields >>

SELECT *
  FROM ztcc_dqm_indices
    INTO TABLE lt_db_indexfields
      WHERE addr_type EQ 1
        ORDER BY index_order.

" << get types >>

LOOP AT lt_db_indexfields ASSIGNING <lfs_db_indexfields>.


  ls_component-name =
    <lfs_db_indexfields>-fieldname.
  ls_component-type ?=
     cl_abap_datadescr=>describe_by_name( <lfs_db_indexfields>-fieldtype ).

  APPEND ls_component TO lt_component.

ENDLOOP.


" --------------------------------------------------------------------- "

" << create struc >>

TRY.

    CALL METHOD cl_abap_structdescr=>create
      EXPORTING
        p_components = lt_component
        p_strict     = abap_true
      RECEIVING
        p_result     = lr_struc_type.

  CATCH cx_sy_struct_creation INTO lr_ex.

    CALL METHOD lr_ex->if_message~get_text
      RECEIVING
        result = lv_error.

    WRITE: / lv_error.

ENDTRY.

" --------------------------------------------------------------------- "
" << create table >>

TRY.
    CALL METHOD cl_abap_tabledescr=>create
      EXPORTING
        p_line_type        = lr_struc_type
*        p_table_kind       = tablekind_std
*        p_unique           = abap_false
*        p_key              = p_key_kind
*        keydefkind_default =
      RECEIVING
        p_result           = lr_table_type.
  CATCH cx_sy_table_creation INTO lr_ex.

    CALL METHOD lr_ex->if_message~get_text
      RECEIVING
        result = lv_error.

    WRITE: / lv_error.
ENDTRY.

" ------------------------------------------------------------------- "

" << create attributs >>

CREATE DATA: ls_dystruc TYPE HANDLE lr_struc_type.

CREATE DATA: lt_dytable TYPE HANDLE lr_table_type.


************************************************************************
* Step 3: << dynamic assignment >>
************************************************************************

ASSIGN lt_dytable->* TO <lfs_indexfields>.

ASSIGN ls_dystruc->* TO <lfs_indexfield>.


" << this works >> 
LOOP AT <lfs_indexfields> ASSIGNING <lfs_indexfield>.

ENDLOOP.

" << i want >> 
READ TABLE lt_dytable 
  INTO ls_dystruc
    WITH KEY .....

. 

Read only

0 Likes
634

Hi,

why don(t you just do

LOOP AT <lfs_indexfields> ASSIGNING <lfs_indexfield> where field1 eq .....

Hope it helps;

Read only

0 Likes
634

Hi saad,

What about performance?

And to refer to my main question.

Is there a generic table type for data declaration?

Thx.

Read only

0 Likes
634

Hello Andreas

You may have a look at the Wiki:

[Creating Flat and Complex Internal Tables Dynamically using RTTI|http://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI]

Regards

Uwe