Application Development 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: 

how to define an internal table which have to be dynamic

Former Member
0 Kudos

Hallo,

here's a problem that i have to solve (but how ?).

I defined an internal Table with 2 columns:

col1: tablename

col2: fieldname

This table is filled with an unknown number of datasets like this:

dataset1: A001 KAPPL

dataset2: A001 KNUMH

dataset3: A903 KUNNR and so on.

I don't know which tablenames and fieldnames are contained.

Now i have to read those fields (e.g. KAPPL) from those tables (e.g. A001) into an internal table.

But i don't know how to define this internal table.

Could anyone help me please ?

Thanks a lot.

Silvio

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Kindly go though the below link .....

[http://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable]

Hope it helps.

Regards

Arbind

5 REPLIES 5

Former Member
0 Kudos

Hi,

Kindly go though the below link .....

[http://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable]

Hope it helps.

Regards

Arbind

0 Kudos

Hi Arbind,

Cause of this link inside your answer i was able to solve my actual problem.

Thanks a lot and have a nice day.

Silvio

0 Kudos

check this out

PROGRAM generic_table_writer.

PARAMETER:
  table TYPE c LENGTH 30 DEFAULT 'SPFLI',
  where TYPE c LENGTH 70 DEFAULT 'carrid = ''AA'''.

DATA:
  data_ref TYPE REF TO data.

FIELD-SYMBOLS:
  <tab> TYPE ANY TABLE.


*&--------------------------------------------------------------------*
*&      Form  write_table
*&--------------------------------------------------------------------*
FORM write_table USING p_table TYPE ANY TABLE.

  FIELD-SYMBOLS: <line>  TYPE data,
                 <field> TYPE data.

  WRITE:/ '{'.
  LOOP AT p_table ASSIGNING <line>.
    WRITE /4 '('.
    DO.
      ASSIGN COMPONENT sy-index OF STRUCTURE <line> TO <field>.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      WRITE /8 <field>.
    ENDDO.            "loop a componente
    WRITE /4 ')'.
  ENDLOOP.            "loop a tabela
  WRITE / '}'.
ENDFORM.              "write_table

START-OF-SELECTION.
  CREATE DATA data_ref TYPE TABLE OF (table).
  ASSIGN data_ref->* TO <tab>.
  SELECT * FROM (table) INTO TABLE <tab> WHERE (where).
  PERFORM write_table USING <tab>.

SuhaSaha
Advisor
Advisor
0 Kudos

You can try something like this:

TYPES:
BEGIN OF TY_DATASET,
  DREF TYPE REF TO DATA,
  FIELD TYPE FIELDNAME,
END OF TY_DATASET.

DATA:
IT_OUTPUT_DATASET TYPE STANDARD TABLE OF TY_DATASET,
WA_OUTPUT_DATASET TYPE TY_DATASET.

FIELD-SYMBOLS: <ITAB> TYPE STANDARD TABLE.

LOOP AT IT_INPUT_DATA INTO WA_INPUT_DATA.
  WA_OUTPUT_DATASET-FIELD = WA_INPUT_DATA-FIELD1.
  CREATE DATA WA_OUTPUT_DATASET-DREF TYPE STANDARD TABLE OF (WA_INPUT_DATA-FIELD2).
  UNASSIGN <ITAB>.
  ASSIGN WA_OUTPUT_DATASET-DREF ->* TO <ITAB>.
  
  CHECK SY-SUBRC = 0.
  SELECT (WA_INPUT_DATA-FIELD1) FROM WA_INPUT_DATA-FIELD2 INTO TABLE <ITAB>.
  APPEND WA_OUTPUT_DATASET TO IT_OUTPUT_DATASET.
  CLEAR: WA_OUTPUT_DATASET, <ITAB>.
ENDLOOP.

Hope this helps.

BR,

Suhas

PS: I don't find any way out other than selecting the data inside the loop. I hope other SDNers agree with me.

Former Member
0 Kudos

Hi Wirth

DATA:
 w_tabname TYPE w_tabname,
 w_dref TYPE REF TO data,
 table_name TYPE tadir-obj_name.
FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE.

READ YOUR INTERNAL TABLE (DATA SET) AND GET THE TABLE NAME,

AND PASS IT TO W_TABNAME.

w_tabname = A001.

CREATE DATA w_dref TYPE TABLE OF (w_tabname).
  ASSIGN w_dref->* TO <t_itab>.

Now use <t_itab> as your internal table to fetch data .

<t_itab> will have the structure of A001.

SELECT *
        FROM (w_tabname) UP TO 10 ROWS
  INTO TABLE <t_itab>.

Regards

Hareesh Menon