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

program with 2 dynamic i_tabs (cl_alv_table_create=>create_dynamic_table)

Former Member
0 Likes
952

Dear Expers

I created a ABAP with dynamic internal table using cl_alv_table_create=>create_dynamic_table more or less according to this example here:

Now I need a second dynamic internal table in the same program. So in a first try I just process the same code a second time (copy+paste) with new variables and new fieldsymbols. But when the program runs and the method is called a second time there is this error: "LT_GENTAB-xyz has laready been declared 7 xyz".

I believe I must free/initialize/delete/undeclare LT_GENTAB before calling the method a second time. Can anybody tell me how to do that? Or is there any other advice on how to create 2 internal tables dynamically in the same program (if possible using the same approach)?

Many thanks

Dear Expers

I created a ABAP with dynamic internal table using cl_alv_table_create=>create_dynamic_table more or less according to this example here:

Now I need a second dynamic internal table in the same program. So in a first try I just process the same code a second time (copy+paste) with new variables and new fieldsymbols. But when the program runs and the method is called a second time there is this error: "LT_GENTAB-xyz has laready been declared 7 xyz".

I believe I must free/initialize/delete/undeclare LT_GENTAB before calling the method a second time. Can anybody tell me how to do that? Or is there any other advice on how to create 2 internal tables dynamically in the same program (if possible using the same approach)?

Many thanks

6 REPLIES 6
Read only

bbalci
Contributor
0 Likes
885

Hi Richard ,

I think you didn't refresh the table LT_GENTAB before your copy code

calling method second time.

Than field XYZ appended into that table again,

a table can not contain two field with same name so you get this error.

Use REFRESH LT_GENTAB.

Read only

Former Member
0 Likes
885

Thanks for your reply.

LT_GENTAB is declared and used somewhere in the SAP standard method. Not in my ABAP. I can not access (or REFRESH) this table in my ABAP. Or if there is a way, could you please let me know how?

Read only

0 Likes
885

Hi,

Here is the sample code from the link in your message :

Filling a table for field declarations :

loop at it_details into wa_details.
  clear wa_it_fldcat.
  wa_it_fldcat-fieldname = wa_details-name .
  wa_it_fldcat-datatype = wa_details-type_kind.
  wa_it_fldcat-inttype = wa_details-type_kind.
  wa_it_fldcat-intlen = wa_details-length.
  wa_it_fldcat-decimals = wa_details-decimals.
  append wa_it_fldcat to it_fldcat .
endloop.

Call the method for dynamic creation :

call method cl_alv_table_create=>create_dynamic_table
             exporting
                it_fieldcatalog = it_fldcat
             importing
                ep_table        = new_table

I meant you didn't refresh table it_fldcat as you fields declaration table.

Did u refresh this table before your second copy code?

Read only

Former Member
0 Likes
885

Thank you for your feedback.

I get your point.

Yes, I acctually used new variables, new fieldsymboles and also new fieldcat for the second run.

I assume there must be a method or something like that to "un-declare" the itab LT_GENTAB before I create a second dynamic table.

Read only

Former Member
0 Likes
885

Nobody?

Read only

MarcinPciak
Active Contributor
0 Likes
885

Don't think you have to reinitialize anything. All you need is somethig like


data: new_table type ref to data,
          new_table2 type ref to data.

"fill field catalog here

"create a table first time
call method cl_alv_table_create=>create_dynamic_table
             exporting
                it_fieldcatalog = it_fldcat
             importing
                ep_table        = new_table

assign new_table->* to <tab1>.

"create similar second table 
call method cl_alv_table_create=>create_dynamic_table
             exporting
                it_fieldcatalog = it_fldcat
             importing
                ep_table        = new_table2

assign new_table2->* to <tab2>.

You could use same data reference variable new_table in both cases but in this case you would loose the connection to your first table after executing this method for the second time.

Regards

Marcin