‎2006 Sep 15 9:47 AM
Hi Everyone,
I am creating dynamic internal table in a loop. I need to retain the created internal tables even after loop. Is it possible, If yes please let me know the way.
‎2006 Sep 15 9:51 AM
Hi
I guess you are creating a dynamic internal table
for each entry of an internal table(within a loop). Do
this via field-symbols, create internal table, do the
processing, unassign it so you can use the same
field-symbol for the next entry in the orginal internal
table.
Kind Regards
Eswar
‎2006 Sep 15 9:53 AM
You can do something like this :
<b>Create a global fieldssymbol</b>
FIELD-SYMBOLS :
<lt_data> TYPE table. " Data to display
Create internal table
CREATE DATA lp_table TYPE STANDARD TABLE OF (p_table)
WITH NON-UNIQUE DEFAULT KEY.
*Assign the internal table created to field symbol
ASSIGN lp_table->* TO <lt_data>.
‎2006 Sep 15 12:47 PM
i DON'T THINK YOU NEED A TABLE OF FIELD-SYmBOLS... but you need a table of data references.
I'm not sure if it will work something like:
types: begin of ty_stuff,
tabname type tabname,
Tdref TYPE REF TO data,
end of ty_stuff.
data w_stuff type ty_stuff.
data t_stuff type table of ty_stuff.
w_stuff-tabname = 'MARA'.
CREATE DATA W_STUFF-tdref TYPE TABLE OF
(w_stuff-tabname).
APPEND W_STUFF TO T_STUFF.
w_stuff-tabname = 'EKPO'.
CREATE DATA W_STUFF-tdref TYPE TABLE OF
(w_stuff-tabname).
Then to access any of the tables (to put data in them or read them etc)
read table t_stuff with key tabname = 'MARA' INTO W_STUFF.
ASSIGN W_STUFF-tdref->* TO <tab>.
‎2006 Sep 18 4:37 AM
CHECK OUT THIS SIMPLE PROGRAM:
REPORT znrw_dyn_tab_multi_KEEP.
PARAMETERS: p_tab1 TYPE tabname, p_tab2 TYPE tabname.
FIELD-SYMBOLS <struc> TYPE ANY.
FIELD-SYMBOLS <tab> TYPE table.
TYPES: BEGIN OF ty_stuff,
tabname TYPE tabname,
tdref TYPE REF TO data,
END OF ty_stuff.
DATA t_stuff TYPE TABLE OF ty_stuff WITH NON-UNIQUE KEY TABNAME.
PERFORM get_data USING p_tab1.
PERFORM get_data USING p_tab2.
PERFORM print USING p_tab2.
PERFORM print USING p_tab1.
&----
*& Form get_data
&----
FORM get_data
USING us_table TYPE tabname.
DATA l_stuff TYPE ty_stuff.
l_stuff-tabname = us_table.
CREATE DATA l_stuff-tdref TYPE TABLE OF
(l_stuff-tabname).
ASSIGN l_stuff-tdref->* TO <tab>.
APPEND l_stuff TO t_stuff.
SELECT * FROM (us_table) UP TO 20 ROWS INTO CORRESPONDING FIELDS OF
TABLE <tab>.
ENDFORM. "get_data
&----
*& Form print
&----
FORM print USING p_tabname TYPE tabname.
DATA l_dref TYPE REF TO data.
DATA l_stuff TYPE ty_stuff.
FIELD-SYMBOLS <field> TYPE ANY.
READ TABLE t_stuff INTO L_stuff WITH KEY tabname = p_tabname.
ASSIGN L_stuff-tdref->* TO <tab>.
CREATE DATA l_dref LIKE LINE OF <tab>.
ASSIGN l_dref->* TO <struc>.
READ TABLE <tab> ASSIGNING <struc> INDEX 1.
WRITE:/ p_tabname.
NEW-LINE.
DO.
*... work through all structure's components...
ASSIGN COMPONENT sy-index OF STRUCTURE <struc> TO <field>.
IF sy-subrc <> 0.
*... exit when reaching the end of components
EXIT.
ENDIF.
WRITE: <field>.
ENDDO.
ENDFORM. " PRINT