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

Create a dynamic internal table name.

Former Member
0 Likes
4,019

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

5 REPLIES 5
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,866

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

Read only

Former Member
0 Likes
1,866

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

Read only

0 Likes
1,866

Then create an internal table of internal tables. (creating a table is appending in the main itab)

(I wrote nothing on dynamic structure ^^)

Regards,

Raymond

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,866

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

Read only

Former Member
0 Likes
1,866
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.