2005 Sep 20 2:12 PM
Hi,
Is there any way to create an internal table dynamically.
My scenario is, I have two internal tables with their field catalog. Now i want ot create a new internal table with fields comprising internal table 1 and 2 without duplication of fields.
thanx for spending your time.
2005 Sep 20 2:30 PM
Hi Arul,
My problem is too. Thanks for God I have been creating internal table. But now my problem is display this dynamic internal table in ALV grid. If you find any answer please send me too. My code :
Source : /people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
My Modified code :
REPORT ZDYNAMIC_INTERNAL .
*Data definitions
*** Tables
DATA: LT_DATA type ref to DATA.
DATA: LT_FIELDCATALOG type LVC_T_FCAT.
*** Structure
DATA: LS_FIELDCATALOG type LVC_S_FCAT.
*** Data References
DATA: NEW_LINE type ref to data,
FS_DATA type ref to data.
*** Field Symbols
FIELD-SYMBOLS: <FS_DATA> type ref to DATA,
<FS_1> type any table,
<FS_2>,
<FS_3>.
*Populating the internal table with fieldnames required for our dynamic
*internal table
LS_FIELDCATALOG-FIELDNAME = 'MANDT'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'CARRID'. "Fieldname
LS_FIELDCATALOG-INTTYPE = 'C'. "Internal Type C-> Character
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'CONNID'.
LS_FIELDCATALOG-INTTYPE = 'N'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'FLDATE'.
LS_FIELDCATALOG-INTTYPE = 'D'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'PRICE'.
LS_FIELDCATALOG-INTTYPE = 'P'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'CURRENCY'.
LS_FIELDCATALOG-INTTYPE = 'C'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
*Calling the method CREATE_DYNAMIC_TABLE
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = LT_FIELDCATALOG
importing
ep_table = FS_DATA
exceptions
generate_subpool_dir_full = 1
others = 2
.
if sy-subrc <> 0.
endif.
*Assigning Field-Symbol to our dynamic internal table
assign LT_DATA to <FS_DATA>.
*Internal Table is ready, now to put data in that table
*** So <FS_1> now points to our dynamic internal table.
assign FS_DATA->* to <FS_1>.
*** Next step is to create a work area for our dynamic internal table.
create data NEW_LINE like line of <FS_1>.
*** A field-symbol to access that work area
assign NEW_LINE->* to <FS_2>.
*** And to put the data in the internal table
select MANDT CARRID CONNID FLDATE PRICE CURRENCY
from SFLIGHT
into corresponding fields of table <FS_1>.
*** Access contents of internal table
loop at <FS_1> assigning <FS_2>.
do 5 times.
assign component sy-index of structure <FS_2> to <FS_3>.
write: <FS_3>.
enddo.
skip 1.
endloop.
2005 Sep 20 2:24 PM
Hi Arul,
Please search the forum for 'dynamic internal table'. You will get lots of post. Many are with sample codes.
Thanks
Vinid
2005 Sep 20 2:25 PM
Hi,
Merge both the field catalogs into a new field catalog internal table and also add suffix "_1" to all field names from the first field catalog table and "_2" to all field names from the second field catalog.
Then use CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE method.
Sri
2005 Sep 20 2:26 PM
Hi,
1) merge fieldcatalog 1 and 2
with fm REUSE_ALV_FIELDCATALOG_MERGE
2) collect fieldcat 1 and 2 to fcat 3
3) build int. table with fm REUSE_ALV_TABLE_CREATE
look this weblogs:
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table
Andreas
Message was edited by: Andreas Mann
2005 Sep 20 2:30 PM
Hi Arul,
My problem is too. Thanks for God I have been creating internal table. But now my problem is display this dynamic internal table in ALV grid. If you find any answer please send me too. My code :
Source : /people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
My Modified code :
REPORT ZDYNAMIC_INTERNAL .
*Data definitions
*** Tables
DATA: LT_DATA type ref to DATA.
DATA: LT_FIELDCATALOG type LVC_T_FCAT.
*** Structure
DATA: LS_FIELDCATALOG type LVC_S_FCAT.
*** Data References
DATA: NEW_LINE type ref to data,
FS_DATA type ref to data.
*** Field Symbols
FIELD-SYMBOLS: <FS_DATA> type ref to DATA,
<FS_1> type any table,
<FS_2>,
<FS_3>.
*Populating the internal table with fieldnames required for our dynamic
*internal table
LS_FIELDCATALOG-FIELDNAME = 'MANDT'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'CARRID'. "Fieldname
LS_FIELDCATALOG-INTTYPE = 'C'. "Internal Type C-> Character
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'CONNID'.
LS_FIELDCATALOG-INTTYPE = 'N'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'FLDATE'.
LS_FIELDCATALOG-INTTYPE = 'D'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'PRICE'.
LS_FIELDCATALOG-INTTYPE = 'P'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'CURRENCY'.
LS_FIELDCATALOG-INTTYPE = 'C'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
*Calling the method CREATE_DYNAMIC_TABLE
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = LT_FIELDCATALOG
importing
ep_table = FS_DATA
exceptions
generate_subpool_dir_full = 1
others = 2
.
if sy-subrc <> 0.
endif.
*Assigning Field-Symbol to our dynamic internal table
assign LT_DATA to <FS_DATA>.
*Internal Table is ready, now to put data in that table
*** So <FS_1> now points to our dynamic internal table.
assign FS_DATA->* to <FS_1>.
*** Next step is to create a work area for our dynamic internal table.
create data NEW_LINE like line of <FS_1>.
*** A field-symbol to access that work area
assign NEW_LINE->* to <FS_2>.
*** And to put the data in the internal table
select MANDT CARRID CONNID FLDATE PRICE CURRENCY
from SFLIGHT
into corresponding fields of table <FS_1>.
*** Access contents of internal table
loop at <FS_1> assigning <FS_2>.
do 5 times.
assign component sy-index of structure <FS_2> to <FS_3>.
write: <FS_3>.
enddo.
skip 1.
endloop.
2005 Sep 20 2:31 PM
hi, you can reference this link:
/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table
for your scenario, compare with the field catalog of internal table 1 & 2. delete the duplication, then using
cl_alv_table_create=create_dynamic_table
or
cl_abap_tabledescr=>create
about the way to delete duplication.
you can have a third internal table itab 3
append itab1 to itab3
append itab2 to itab3
sort itab3
DELETE ADJACENT DUPLICATES FROM ITAB3 COMPARING fieldname.
hope it will be helpful
thanks