2010 Oct 13 12:41 PM
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
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
2010 Oct 13 12:59 PM
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.
2010 Oct 13 1:14 PM
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?
2010 Oct 13 1:26 PM
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_tableI meant you didn't refresh table it_fldcat as you fields declaration table.
Did u refresh this table before your second copy code?
2010 Oct 13 3:38 PM
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.
2010 Oct 19 12:43 PM
2010 Oct 19 1:19 PM
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
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |