2023 Oct 17 4:18 PM
Hi,
I have an internal table ( say table_1) in which 1 field ( KOTABNR ) holds the table name.
I need to loop at table_1 and have to create as many internal tables as there are entries in the field KOTABNR.
I am not able to declare field symbol names dynamically so that I can identify which table is created against a particular entry in table_1.
Please help on the issue.
Thanks
2023 Oct 18 8:30 AM
Try something like
TYPES: BEGIN OF ty_table,
tabname TYPE tabname,
contents TYPE REF TO DATA,
END OF ty_table.
TYPES ty_tables TYPE HASHED TABLE OF ty_table.
DATA tables TYPE ty_tables.
LOOP AT kobog_temp INTO kobog.
DATA(tablename) = 'A' && kobog-kotabnr.
INSERT VALUE #( tabname = tablename ) INTO TABLE tables
ASSIGNING FIELD-SYMBOL(<table>).
CREATE DATA <table>-contents TYPE TABLE OF (tablename).
FIELD-SYMBOLS <contents> TYPE STANDARD TABLE.
ASSIGN <table>-contents->* to <contents>.
SELECT * INTO TABLE <contents> FROM (tablename)
FOR ALL ENTRIES IN konaind
WHERE knumh = koonaind-knumh.
ENDLOOP.
Then, when you need to read one of the tables, something like
FIELD-SYMBOLS <contents> TYPE STANDARD TABLE.
ASSIGN tables[ tabname = tablename ]-contents-> TO <contents>.
2023 Oct 17 6:36 PM
The declaration of a field symbol is somewhat "dynamic":
FIELD-SYMBOLS <ITAB> TYPE ANY TABLE.
Each time you need to access one of the many internal tables, you do:
ASSIGN dref_itab->* TO <itab>.
Post your code if you're still not clear with the concept.
2023 Oct 17 11:03 PM
I am adding code snippet. Table lt_kobog_temp has a field KOTABNR which has values for condition tables like 901, 902.....and we have to prepare internal table dynamically like it_a901, it_902..so that after loop, i can read each table in sequence .
In the below code, only one internal table <f_itab> gets created. If somehow, I can declare field symbol name dynamically inside loop, then i can create many internal tables dynamically but right now, i am unable to achieve it.
FIELD-SYMBOLS : <f_itab> TYPE ANY TABLE.lv_table TYPE tabname.
* Now preparing the tableENDLOOP.
2023 Oct 18 8:30 AM
Try something like
TYPES: BEGIN OF ty_table,
tabname TYPE tabname,
contents TYPE REF TO DATA,
END OF ty_table.
TYPES ty_tables TYPE HASHED TABLE OF ty_table.
DATA tables TYPE ty_tables.
LOOP AT kobog_temp INTO kobog.
DATA(tablename) = 'A' && kobog-kotabnr.
INSERT VALUE #( tabname = tablename ) INTO TABLE tables
ASSIGNING FIELD-SYMBOL(<table>).
CREATE DATA <table>-contents TYPE TABLE OF (tablename).
FIELD-SYMBOLS <contents> TYPE STANDARD TABLE.
ASSIGN <table>-contents->* to <contents>.
SELECT * INTO TABLE <contents> FROM (tablename)
FOR ALL ENTRIES IN konaind
WHERE knumh = koonaind-knumh.
ENDLOOP.
Then, when you need to read one of the tables, something like
FIELD-SYMBOLS <contents> TYPE STANDARD TABLE.
ASSIGN tables[ tabname = tablename ]-contents-> TO <contents>.
2023 Oct 18 9:14 AM