2009 Feb 26 11:47 AM
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
2009 Feb 26 11:51 AM
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.
2009 Feb 26 11:53 AM
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.
2009 Feb 27 1:48 PM
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
2009 Feb 27 1:54 PM
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к
2009 Feb 27 1:58 PM
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
2009 Feb 27 10:52 PM
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.
2009 Feb 28 6:40 AM
<copy&paste_removed_by_moderator>
Edited by: Julius Bussche on Mar 1, 2009 8:07 PM
2009 Mar 01 7:05 PM
Hi Neelima,
Source of ur answer
http://www.henrikfrank.dk/abaptips/abap%20language/dynamic%20programming/dynamicopensql.htm
кu03B1ятu03B9к
2009 Mar 01 7:22 PM
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
2009 Mar 02 6:01 AM
hi somnath,
Do you want all the internal tables of the same structure?
Regards,
Bhumika