‎2007 Apr 14 10:42 AM
hi all
I have a particular internal table in memory area( thru EXPORT TO MEMORY ID ....)
how can i create an internal table of this type in another program at runtime ?
this internal table need not be a data dictionary type.
i.e., i need to create an internal table of type which
is stored in a particular memory-id.
Regards,
Naveen........
null
‎2007 Apr 14 10:51 AM
Hi,
Check this code :
TYPE-POOLS: slis.
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
<fs_dyntable>,
<fs_fldval> type any.
PARAMETERS: p_cols(5) TYPE c.
DATA: t_newtable TYPE REF TO data,
t_newline TYPE REF TO data,
t_fldcat TYPE slis_t_fldcat_alv,
t_fldcat TYPE lvc_t_fcat,
wa_it_fldcat TYPE lvc_s_fcat,
wa_colno(2) TYPE n,
wa_flname(5) TYPE c.
* Create fields .
DO p_cols TIMES.
CLEAR wa_it_fldcat.
move sy-index to wa_colno.
concatenate 'COL'
wa_colno
into wa_flname.
wa_it_fldcat-fieldname = wa_flname.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
ENDDO.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable.
ASSIGN t_newtable->* TO <t_dyntable>.
* Create dynamic work area and assign to FS
CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
ASSIGN t_newline->* TO <fs_dyntable>.
-
DATA it_fieldcatalog TYPE lvc_t_fcat.
DATA lr_table TYPE REF TO data.
FIELD-SYMBOLS <lt_table> TYPE table.
*-- Import the fieldcatalog
IMPORT it_fieldcatalog TO it_fieldcatalog
FROM MEMORY ID 'CREATE_DYNAMIC_TABLE'.
IF sy-subrc <> 0.
EXIT.
ENDIF.
*-- Create the dynamic table with the field catalog as structure
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcatalog
IMPORTING
ep_table = lr_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
*-- Convert the reference into a table
ASSIGN lr_table->* TO <lt_table>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
*-- Export the created table so that the function module can import it
EXPORT lt_table FROM <lt_table>
TO MEMORY ID 'CREATE_DYNAMIC_TABLE'.
Regards
L Appana