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

sorted table by using method create_dynamic_table

Former Member
0 Likes
725

<l_table1> is defined as an sorted table and new_table from method create_dynamic_table is coming as standard table.

when we write a statement "ASSIGN new_table1->* TO <l_table1>." Its giving runtime error type conflict.

Could you please let me know how to create sorted internal table by using method create_dynamic_table.

  • Create a new Table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat1

IMPORTING

ep_table = new_table1.

  • Create a new Line with the same structure of the table.

ASSIGN new_table1->* TO <l_table1>.

4 REPLIES 4
Read only

venkat_o
Active Contributor
0 Likes
640

Hi, <li><l_table1>and new_table1 should be declared like below. <li>Fieldcatalog must be created before we call CALL METHOD cl_alv_table_create=>create_dynamic_table.

    DATA:it_dyn_tab   TYPE REF TO data.
    "Filed symbols
    FIELD-SYMBOLS:<gt_table>   TYPE STANDARD TABLE.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = it_fcat
      IMPORTING
        ep_table        = it_dyn_tab.
    ASSIGN it_dyn_tab->* TO <gt_table>.
I hope that it helps u . Thanks Venkat.O

Read only

Former Member
0 Likes
640

Hi,

The code which you have sent me is working fine. but i want to have <gt_table> as sorted table not as standard table. I just wanted to use binary seach on <gt_table> and for that it needs to be sorted table.

Could you please help me with that.

Regards

Read only

venkat_o
Active Contributor
0 Likes
640

Hi, <li>Difficult to define SORTED dynamic table because, We do not know the structure and fields until run time. For SORTED tables, We need to specify key fields. We do not know fields so defining key fields highly impossible. <li>If you want to use addition BINARY SEARCH, We can even use that for STANDARD TABLES. <li>If the addition BINARY SEARCH is specified, the search is binary instead of linear. This considerably reduces the runtime of the search for larger tables (from approximately 100 entries upwards). <li>For the binary search, the table must be sorted by the specified search key in ascending order. Otherwise the search will not find the correct row. Thanks Venkat.O

Read only

former_member212005
Active Contributor
0 Likes
640

It is difficult to create a sorted internal table...

Check the below link which tells you how to do it...

However, if you have defined it as STANDARD TABLE then you can sort it using the below statement...

SORT <lt_tab> BY (c_fieldname).

hope it helps!