‎2007 Apr 02 10:34 AM
Hi All,
I want to generate internal tables depending upon the no. of lines in the internal table . For example if there are 5 rows in an internal table itab, then I want to generate 5 internal tables of name like itab1, itab2 itab3 itab4 itab5. Is there any way to do this??
Pls Suggest.
Thanks
‎2007 Apr 02 10:38 AM
Hi,
Check this code.
DATA path LIKE ibipparms-path.
DATA: i_excel LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.
data: i_fcat type LVC_T_FCAT,
wa_fcat type lvc_s_fcat.
data: fname(10),
I_PTABLE TYPE REF TO DATA.
SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-001.
PARAMETERS p_path LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b.
FIELD-SYMBOLS: <fs_final> TYPE ANY,
<I_TABLE> type table.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = path.
p_path = path.
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_path
i_begin_col = 1
i_begin_row = 1
i_end_col = 256
i_end_row = 65536
TABLES
intern = i_excel.
loop at i_excel where row = '1'.
wa_fcat-ROW_POS = i_excel-row.
wa_fcat-col_pos = i_excel-col.
concatenate 'COL_' i_excel-col into fname.
wa_fcat-FIELDNAME = I_EXCEL-VALUE.
append wa_fcat to i_fcat.
endloop.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = I_FCAT
IMPORTING
EP_TABLE = I_PTABLE.
Assign i_ptable->* to <i_table>.
perform zf_assign.
End-of-selection.
LOOP AT I_FCAT INTO WA_FCAT .
WRITE: WA_FCAT-FIELDNAME(10).
ENDLOOP.
LOOP AT <I_TABLE> assigning <fs_final>.
WRITE:/ <fs_final>.
ENDLOOP.
&----
*& Form zf_assign
&----
text
----
--> p1 text
<-- p2 text
----
form zf_assign .
field-symbols: <ls_table>.
ASSIGN LOCAL COPY OF INITIAL LINE OF <I_TABLE> TO <LS_TABLE>.
LOOP AT i_excel WHERE ROW <> 1.
ASSIGN COMPONENT i_excel-col OF STRUCTURE <LS_TABLE> TO <fs_final>.
<fs_final> = i_excel-value.
AT END OF row.
APPEND <LS_TABLE> TO <i_table>.
ENDAT.
ENDLOOP.
unassign <ls_table>.
endform. " zf_assign
‎2007 Apr 02 10:38 AM
you can create dynamic table using field symbol.
and by calling floowing method:
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
‎2007 Apr 02 10:39 AM
hello,
try this:
FIELD-SYMBOL <fs_table> TYPE TABLE.
Create dynamic table (according to fieldcatalog)
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcatalog
IMPORTING
ep_table = lr_table.
ASSIGN lr_table->* TO <fs_table>.
‎2007 Apr 02 10:45 AM
HI All,
Thanks for all ur replies but my requirement is different.
I want to generate internal table dynamically but the here dynamic is the number of internal tables to be generated not the structure of the internal table. The structure is same but I have to generate as many internal table as there are rows in the other internal table.
Message was edited by:
Manik Dhakate
‎2007 Apr 02 10:47 AM
Use describe table to find number of lines in the internal table.
then create dynamic internal tables .
Use do n times. " n is num of lines in ur master itab
create dynamic internal table
enddo.
‎2007 Apr 02 10:51 AM
Hi Azeem,
Thanks for ur reply I tried the way u said but it is giving some error.
I Am posting the code which I tried,
LOOP AT it_matmaster.
int = sy-tabix.
DATA: begin of it_data + int occurs 0.
include structure STPOX.
DATA: end of it_data+int.
endloop.
Plz Suggest.
Thanks
‎2007 Apr 02 10:43 AM
hi manik
dynamic tables can be created by
function module BCALV_TABLE_CREATE
another method is
With the help of Class cl_alv_table_create
and the method create_dynamic_table , you can create Dynamic Internal Tables
also go thro these blogs these mite help
<a href="/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table:///people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table
<a href="/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap:///people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
regards
navjot
reward for helpfull answers
‎2007 Apr 02 10:45 AM
manik,
Find the totla number of rows in Internal table by using Syntax
" Describe table xxxx lines v_line"
Use do loop v_line times where the columns and name of the table getting assigned in below coding.
-
type-pools : abap.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.
start-of-selection.
perform get_structure.
perform create_dynamic_itab. *********Creates a dyanamic internal table*********
perform get_data.
perform write_out.
form get_structure.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform.
form create_dynamic_itab.
Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = ifc
importing
ep_table = dy_table.
assign dy_table->* to <dyn_table>.
Create dynamic work area and assign to FS
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
endform.
form get_data.
Select Data from table.
select * into table <dyn_table>
from (p_table).
endform.
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
-
REPORT ZCLUST1 .
Example: how to create a dynamic internal table
The dynamic internal table stucture
DATA: BEGIN OF STRUCT OCCURS 10,
FILDNAME(8) TYPE C,
ABPTYPE TYPE C,
LENGTH TYPE I,
END OF STRUCT.
The dynamic program source table
DATA: BEGIN OF INCTABL OCCURS 10,
LINE(72),
END OF INCTABL.
DATA: LNG TYPE I, TYPESRTING(6).
Sample dynamic internal table stucture
STRUCT-FILDNAME = 'field1'. STRUCT-ABPTYPE = 'c'. STRUCT-LENGTH = '6'.
APPEND STRUCT. CLEAR STRUCT.
STRUCT-FILDNAME = 'field2'. STRUCT-ABPTYPE = 'd'.
APPEND STRUCT. CLEAR STRUCT.
STRUCT-FILDNAME = 'field3'. STRUCT-ABPTYPE = 'i'.
APPEND STRUCT. CLEAR STRUCT.
Create the dynamic internal table definition in the dyn. program
INCTABL-LINE = 'program zdynpro.'. APPEND INCTABL.
INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.
LOOP AT STRUCT.
INCTABL-LINE = STRUCT-FILDNAME.
LNG = STRLEN( STRUCT-FILDNAME ).
IF NOT STRUCT-LENGTH IS INITIAL .
TYPESRTING(1) = '('.
TYPESRTING+1 = STRUCT-LENGTH.
TYPESRTING+5 = ')'.
CONDENSE TYPESRTING NO-GAPS.
INCTABL-LINE+LNG = TYPESRTING.
ENDIF.
INCTABL-LINE+15 = 'type '.
INCTABL-LINE+21 = STRUCT-ABPTYPE.
INCTABL-LINE+22 = ','.
APPEND INCTABL.
ENDLOOP.
INCTABL-LINE = 'end of dyntab. '.
APPEND INCTABL.
Create the code processes the dynamic internal table
INCTABL-LINE = ' '. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = ''aaaaaa''.'. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = ''19970814''.'. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = 1.'. APPEND INCTABL.
INCTABL-LINE = 'append dyntab.'. APPEND INCTABL.
INCTABL-LINE = ' '. APPEND INCTABL.
INCTABL-LINE = 'loop at dyntab.'. APPEND INCTABL.
INCTABL-LINE = 'write: / dyntab.'. APPEND INCTABL.
INCTABL-LINE = 'endloop.'. APPEND INCTABL.
Create and run the dynamic program
INSERT REPORT 'zdynpro'(001) FROM INCTABL.
SUBMIT ZDYNPRO.
-
or Just try out this simpler dynamic internal tables
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.
Pls. reward if useful
‎2007 Apr 02 11:10 AM
Hi,
for this u have to use the function module "rss_template_instantiate".
then only it is ppossible to generate the program dynamically according to ur requirement.
regards,
bharat.