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

Unable to create Dynamic internal Table

Former Member
0 Likes
1,853

Hi All

Here is the code i have written to create dynamic internal table


  DATA : idetails TYPE abap_compdescr_tab,
       xdetails TYPE abap_compdescr.
  DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
  UNASSIGN: <dyn_table>, <dyn_wa>, <dyn_field>.
* Get the structure of the table.
  ref_table_des ?=
      cl_abap_typedescr=>describe_by_name( table-low ).
  idetails[] = ref_table_des->components[].
  w_out-rec = table-low.
  APPEND w_out TO i_out.
  CLEAR w_out.
  LOOP AT idetails INTO xdetails.
    CLEAR xfc.
    xfc-fieldname = xdetails-name.
    CONCATENATE w_out xdetails-name INTO w_out
                    SEPARATED BY ','.
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    APPEND xfc TO ifc.
  ENDLOOP.
  APPEND w_out TO i_out.
* Create dynamic internal table and assign to FS
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = ifc
    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>.

the 1st internal table is created successfully

when it is executing the class cl_alv_table_create=>create_dynamic_table

for creating the 2nd internal table, it errors out.

Error message

"LT_GENTAB-MANDT" has already been declared. 9 MANDT(000006)

Please let me know how to solve this.

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
1,216

Please change the code this way and try


 LOOP AT idetails INTO xdetails.
    CLEAR xfc.
    xfc-fieldname = xdetails-name.
    CONCATENATE w_out xdetails-name INTO w_out
                    SEPARATED BY ','.
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    read table ifc with key fieldname = xfc-fieldname. "<
    if sy-subrc ne 0.                                  "<
    APPEND xfc TO ifc.                                 "<  
    endif.
  ENDLOOP.

Hi All

Here is the code i have written to create dynamic internal table


  DATA : idetails TYPE abap_compdescr_tab,
       xdetails TYPE abap_compdescr.
  DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
  UNASSIGN: <dyn_table>, <dyn_wa>, <dyn_field>.
* Get the structure of the table.
  ref_table_des ?=
      cl_abap_typedescr=>describe_by_name( table-low ).
  idetails[] = ref_table_des->components[].
  w_out-rec = table-low.
  APPEND w_out TO i_out.
  CLEAR w_out.
  LOOP AT idetails INTO xdetails.
    CLEAR xfc.
    xfc-fieldname = xdetails-name.
    CONCATENATE w_out xdetails-name INTO w_out
                    SEPARATED BY ','.
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    APPEND xfc TO ifc.
  ENDLOOP.
  APPEND w_out TO i_out.
* Create dynamic internal table and assign to FS
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = ifc
    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>.

the 1st internal table is created successfully

when it is executing the class cl_alv_table_create=>create_dynamic_table

for creating the 2nd internal table, it errors out.

Error message

"LT_GENTAB-MANDT" has already been declared. 9 MANDT(000006)

Please let me know how to solve this.

6 REPLIES 6
Read only

former_member194669
Active Contributor
0 Likes
1,217

Please change the code this way and try


 LOOP AT idetails INTO xdetails.
    CLEAR xfc.
    xfc-fieldname = xdetails-name.
    CONCATENATE w_out xdetails-name INTO w_out
                    SEPARATED BY ','.
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    read table ifc with key fieldname = xfc-fieldname. "<
    if sy-subrc ne 0.                                  "<
    APPEND xfc TO ifc.                                 "<  
    endif.
  ENDLOOP.

Read only

0 Likes
1,216

but now it goes to short dump on the select query


  LOOP AT table.
    PERFORM create_dynamic_itab.
    SELECT * INTO TABLE <dyn_table>
                FROM (table-low).
    PERFORM fill_it.
  ENDLOOP.

Short Dump Description

Short text

The types of operands "dbtab" and "itab" cannot be converted into one another.

Error analysis

In a Unicode system, the type of the operand "dbtab" must be convertible

into that of the operand "itab" for the statement "SELECT * FROM dbtab INTO

TABLE itab". Regardless of the

length of a Unicode character, both operands must have the same

structure layout.

In this case, this condition has not been met.

i checked the fields, they are same

If i change the select statement clause to


into corresponding fields

it is going to dump in PERFORM fill_it. statement.

Read only

0 Likes
1,216

What will be he code in FILL_IT ?

Read only

0 Likes
1,216

FORM fill_it.
*   Write out data from table.
  LOOP AT <dyn_table> INTO <dyn_wa>.
    CLEAR w_out.
    DO.
      ASSIGN COMPONENT  sy-index
         OF STRUCTURE <dyn_wa> TO <dyn_field>.
      IF sy-subrc <> 0.
        APPEND w_out TO i_out.
        EXIT.
      ELSE.
        CONCATENATE w_out <dyn_field>
                INTO w_out SEPARATED BY ','.
      ENDIF.
    ENDDO.
  ENDLOOP.
ENDFORM.                    "fill_it
Read only

Former Member
0 Likes
1,216

Hi Sairam,

What do u mean by 2nd internal table creation.

Will it happen in the same ABAP session or a different session.

The errors is with respect to duplication of fields. When u declare two fields with same name in an internal table , it will throw an error message. The same thing is happening when u r creating an internal table dynamically.

-Satya Priya

Read only

Former Member
0 Likes
1,216

Try clearing the field catalog table ifc. U can check the fields of this fieldcatalog table in debugging mode.

-Satya Priya