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

Creating Dynamic internal tables

Former Member
0 Likes
1,202

Hi,

My post is not to know how to create Dynamic internal tables but to know how to create dynamic internal tables for which I don't know how many dynamic tables are supposed to be created during run time.

Means, I don't know how many internal tables I would need during run time but I know the attributes of the table that is supposed to be created!

Is it possible ?

Please put your thoughts on this.

Thanks,

Somnath

10 REPLIES 10
Read only

Former Member
0 Likes
1,038

I dont think that this is possible but i´m not a 100% sure.

You could declare just that much itabs to be sure they are enough.

Read only

Former Member
0 Likes
1,038

Hi,

Yes , you can create a Dynamic Internal table.

Simple example program.

DATA: itab TYPE STANDARD TABLE OF spfli,

wa LIKE LINE OF itab.

DATA: line(72) TYPE c,

list LIKE TABLE OF line(72).

START-OF-SELECTION.

*line = ' CITYFROM CITYTO '.

line = ' AIRPTO '.

APPEND line TO list.

SELECT DISTINCT (list)

INTO CORRESPONDING FIELDS OF TABLE itab

FROM spfli.

IF sy-subrc EQ 0.

LOOP AT itab INTO wa.

  • WRITE: / wa-cityfrom, wa-cityto.

WRITE 😕 wa-airpto.

ENDLOOP.

ENDIF.

Thanks,

Neelima.

Read only

0 Likes
1,038

Hi ,

Thanks for the reply.

But I didn't get the correct answer. I think my question was not properly placed.

Anyway I am repeating the same.

I don't know how many internal tables I would need during run time but I know what would be the structure for those table during run time. Is there any way to dynamically declare those many field-symbols through which can capture those table references created dynamically ?

Hope the question is clear now !

Thanks

Somnath

Read only

0 Likes
1,038

i dont think u can have a control on number of field symbols or itabs to be created so its better u anticipate the maximum number and predeclare them in ur code.

кu03B1ятu03B9к

Read only

ThomasZloch
Active Contributor
0 Likes
1,038

Should all tables have the same structure? Why not add an additional key field, like a counter, or use deep structures, i.e. an internal table containing internal tables.

Thomas

Read only

Former Member
0 Likes
1,038

Wrap your internal table in a local class. Then create in itab of the local class. This will allow you to instance the table at will at runtime. Of course you will need methods to access the table.


CLASS myITABCLASS DEFINITION .

PUBLIC SECTION .

* Define methods for dealing with internal table here

PROTECTED SECTION .

PRIVATE SECTION .

*  Define internal Table here

ENDCLASS .

CLASS myITABCLASS IMPLEMENTATION .

* Implement the methods from above here.

ENDCLASS .

* In program
DATA waClTab TYPE REF TO myITABCLASS .

DATA itCITab TYPE STANDARD TABLE OF REF TO myITABCLASS .

* Now every time you need another table, you use the following
CREATE OBJECT waClTab .

APPEND waClTab TO itClTab .

This will allow you to create as many internal tables as you would like. In addition, if you need multiple structures for your tables, you could create a base class and have your table structures inherit the base class. This would allow for an indefinite number of varied table structures.

Read only

Former Member
0 Likes
1,038

<copy&paste_removed_by_moderator>

Edited by: Julius Bussche on Mar 1, 2009 8:07 PM

Read only

0 Likes
1,038
Read only

karol_seman
Active Participant
0 Likes
1,038

Hi,

create a dynamic table assigned to field symbol with type any (use create data statement). Then create an internal table which has type declared as "TYPE REF TO DATA" - this is an universal table which can hold any number of records and each record can have different structure. For easy use you can create this table with two columns. First one contains type of the structure and second one contains variable.

In this way it doesn't matter how many tables you have.

Regards,

Karol

Read only

Former Member
0 Likes
1,038

hi somnath,

Do you want all the internal tables of the same structure?

Regards,

Bhumika