‎2009 Nov 24 8:26 AM
Hi,
My requirement is like the below.
do n times.
data : itab<n> type table of <>.
enddo.
Itab1 itab2 iab3 -
itabn are to be created based on the sy-index.
Any body have any idea how to achieve this.
Regards,
Surendar Reddy.
‎2009 Nov 24 11:52 AM
Hi
Check this sample code for logic
DATA :ITAB_NAM(6) TYPE C.
DATA :ITAB_NAME(40) TYPE C.
DATA:W_IND(2) TYPE C.
DO 5 TIMES.
W_IND = SY-INDEX.
CONCATENATE 'itab' W_IND INTO ITAB_NAM.
CONCATENATE 'DATA' ':' ITAB_NAM 'TYPE' 'STANDARD' 'TABLE' 'OF' INTO ITAB_NAME SEPARATED BY SPACE.
WRITE : ITAB_NAME.
ENDDO.
with regards
anand Kumar
‎2009 Nov 24 11:52 AM
Hi
Check this sample code for logic
DATA :ITAB_NAM(6) TYPE C.
DATA :ITAB_NAME(40) TYPE C.
DATA:W_IND(2) TYPE C.
DO 5 TIMES.
W_IND = SY-INDEX.
CONCATENATE 'itab' W_IND INTO ITAB_NAM.
CONCATENATE 'DATA' ':' ITAB_NAM 'TYPE' 'STANDARD' 'TABLE' 'OF' INTO ITAB_NAME SEPARATED BY SPACE.
WRITE : ITAB_NAME.
ENDDO.
with regards
anand Kumar
‎2009 Nov 24 12:45 PM
Well, what may be working is something like this
TYPES: BEGIN OF ts_tables,
index LIKE sy-index,
ref TYPE REF TO data,
END OF ts_tables.
TYPES: ts_dynamic_table TYPE soli.
TYPES: tt_dynamic_table TYPE STANDARD TABLE OF ts_dynamic_table WITH DEFAULT KEY.
DATA: lt_tables TYPE HASHED TABLE OF ts_tables WITH UNIQUE KEY index.
DATA: ls_tables TYPE ts_tables.
DATA: ls_dynamic_table TYPE ts_dynamic_table.
FIELD-SYMBOLS: <table> TYPE ANY TABLE.
FIELD-SYMBOLS: <lt_tables> LIKE LINE OF lt_tables.
* Creating Tables
DO 5 TIMES.
ls_tables-index = sy-index.
CREATE DATA ls_tables-ref TYPE tt_dynamic_table.
INSERT ls_tables INTO TABLE lt_tables.
ENDDO.
* Accessing Tables
DO 5 TIMES.
READ TABLE lt_tables ASSIGNING <lt_tables> WITH TABLE KEY index = sy-index.
IF ( sy-subrc = 0 ).
ASSIGN <lt_tables>-ref->* TO <table>.
ls_dynamic_table-line = sy-index.
INSERT ls_dynamic_table INTO TABLE <table>.
ENDIF.
ENDDO.
This example dynamically creates 5 internal tables of structure soli which are accessible by an index, and write a single line to each one of them.
Edited by: Carsten Grafflage on Nov 24, 2009 1:49 PM
Edited by: Carsten Grafflage on Nov 24, 2009 1:51 PM (renamed field)
‎2009 Nov 24 1:06 PM
REPORT abc.
CLASS l_table DEFINITION.
PUBLIC SECTION.
data : itab type standard table of mara.
endclass.
CLASS l_table IMPLEMENTATION.
ENDCLASS.
types : begin of ty_tables,
index type sy-tabix,
lc_ref type ref to l_table,
end of ty_tables.
START-OF-selection.
data : i_tables type STANDARD TABLE OF ty_tables,
wa_tables type ty_tables.
do 3 times.
wa_tables-index = sy-index.
create object wa_tables-lc_ref.
append wa_tables to i_tables.
enddo.
this code will create internal table of type mara only..If you want dynamic internal tables , please search for dynamic internal tables and modify this code accordingly.
you have one internal table for each instance of the class as an attribute . access your internal tables as per your requirement