2011 Jun 29 1:02 PM
Hello gurus,
I need to create an internal table in runtime. I don´t need to create the table catalog dynamically, I need to create the internal table name in a dynamic way. For example:
DO 25 TIMES
"CREATE AN INTERNAL TABLE WITH NAME 'IT_TABLE_' + SY-TABIX.
"FILL THE TABLE
"ETC
ENDDO.
Thank you very much and kind regards
Ibai
2011 Jun 29 1:10 PM
Look at SAP Abap documentation for [CREATE DATA|http://help.sap.com/abapdocu_70/en/ABAPCREATE_DATA.htm] and [CREATE DATA - TABLE OF|http://help.sap.com/abapdocu_70/en/ABAPCREATE_DATA_ITAB.htm]. You could create an internal table of reference to internal tables for your kind of requirement.
Regards,
Raymond
2011 Jun 29 1:15 PM
Thanks Raymond,
I have already seen this, but It si not helpfull, I need to create an internal table with a dynamic name, not with a dinamic structure.
The structure is the same for each internal tabla, I just need tocreate any number of diferent internal tabls with diferente names,
Regars,
Ibai
2011 Jun 29 1:22 PM
2011 Jun 29 1:24 PM
Hello,
Check this code snippet:
TYPES:
BEGIN OF gty_dyntab,
name TYPE string, "Int. table name
data TYPE REF TO data, "Int. table data
END OF gty_dyntab.
DATA: gv_table TYPE dd02l-tabname,
gt_dyntab TYPE STANDARD TABLE OF gty_dyntab,
gs_dyntab TYPE gty_dyntab,
gv_index TYPE numc2.
SELECT-OPTIONS: s_table FOR gv_table NO INTERVALS.
LOOP AT s_table.
* Populate the int. table name
WRITE sy-index TO gv_index NO-ZERO.
CONCATENATE 'IT_TABLE' gv_index INTO gs_dyntab-name.
* Create the int. table
CREATE DATA gs_dyntab-data TYPE STANDARD TABLE OF (s_table-low).
APPEND gs_dyntab TO gt_dyntab. CLEAR gs_dyntab.
ENDLOOP.For the sake of simplicity i've used a simple version of CREATE DATA. Based on your requirement you can use this construct or the RTTC classes to generate the dynamic type.
BR,
Suhas
2011 Jun 29 2:59 PM
DATA: lt_field TYPE lvc_t_fcat,
rt_field TYPE STANDARD TABLE OF lty_field,
lt_ref_tb TYPE REF TO data,
lx_wa TYPE REF TO data.FIELD-SYMBOLS : <fs_table> TYPE STANDARD TABLE,
<fs_wa> TYPE ANY.
**************************************************************************
Fill the internal table lt_field with field names and ref table names
**************************************************************************
*Create dynamic table from field catalog
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_field
IMPORTING
ep_table = lt_ref_tb
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc EQ 0.
ASSIGN lt_ref_tb->* TO <fs_table>.
CHECK sy-subrc EQ 0.
CREATE DATA lx_wa LIKE LINE OF <fs_table>.
ASSIGN lx_wa->* TO <fs_wa>.
CHECK sy-subrc EQ 0.
ENDIF.