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

creating dynamic sorted internal table.

Former Member
0 Likes
1,791

<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>.

1 ACCEPTED SOLUTION
Read only

alejiandro_sensejl
Active Participant
943

Hello Veerendranath Pichikala,

you have to use method CREATE of class CL_ABAP_TABLEDESCR. Here you can define the type of the table via parameter P_TABLE_KIND (e.g.TABLEKIND_SORTED for sorted table).

As an example you can have a look at the following snippet from the article Advanced and Generic Programming in ABAP by Björn Mielenhausen and Gerd Kluger.


DATA: lineType  TYPE REF TO cl_abap_structdescr,
      tableType TYPE REF TO cl_abap_tabledescr,
      key       TYPE abap_keydescr_tab.
      
lineType ?= cl_abap_typedescr=>describe_by_name( 'SPFLI' ).

APPEND 'CARRID' TO key. 
APPEND 'CONNID' TO key.

tableType = cl_abap_tabledescr=>create(
              p_line_type  = lineType
              p_table_kind = cl_abap_tabledescr=>tablekind_sorted
              p_unique     = abap_true
              p_key        = key ).

Best regards,

Alej

2 REPLIES 2
Read only

alejiandro_sensejl
Active Participant
944

Hello Veerendranath Pichikala,

you have to use method CREATE of class CL_ABAP_TABLEDESCR. Here you can define the type of the table via parameter P_TABLE_KIND (e.g.TABLEKIND_SORTED for sorted table).

As an example you can have a look at the following snippet from the article Advanced and Generic Programming in ABAP by Björn Mielenhausen and Gerd Kluger.


DATA: lineType  TYPE REF TO cl_abap_structdescr,
      tableType TYPE REF TO cl_abap_tabledescr,
      key       TYPE abap_keydescr_tab.
      
lineType ?= cl_abap_typedescr=>describe_by_name( 'SPFLI' ).

APPEND 'CARRID' TO key. 
APPEND 'CONNID' TO key.

tableType = cl_abap_tabledescr=>create(
              p_line_type  = lineType
              p_table_kind = cl_abap_tabledescr=>tablekind_sorted
              p_unique     = abap_true
              p_key        = key ).

Best regards,

Alej

Read only

Former Member
0 Likes
943

Check the following (It's working and in 4.6 Version). The code is part of a Rich Heilman's Blog.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<dyn_field>.

data: dy_table type ref to data,

dy_line type ref to data.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = (fieldcatalog)

importing

ep_table = dy_table.

assign dy_table->* to <dyn_table>.

  • Create dynamic work area and assign to FS

create data dy_line like line of <dyn_table>.

assign dy_line->* to <dyn_wa>.

With regards

George