‎2006 Dec 19 1:42 PM
Hi,
I need to define at runtime an internal table.
In particular let p_type the parameter to define the type for an internal table
DATA: itab TYPE STANDARD TABLE
OF p_type
WITH HEADER LINE.
This code doesn't work.
I have tryed to use a field-symbol but same result.
Any suggest?
‎2006 Dec 19 1:55 PM
hi
good
try this
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.
thanks
mrutyun^
‎2006 Dec 19 1:55 PM
hi,
try the following.
data: itab type ref to data.
field-symbols: <itab> type standard table.
CREATE DATA itab TYPE STANDARD TABLE OF (p_type).
assign itab->* to <itab>.
Regards
Sebastian
‎2006 Dec 19 1:55 PM
hi
good
try this
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.
thanks
mrutyun^
‎2006 Dec 19 2:17 PM
It works correctly! Very good!
Just a last question to solve completely my problem.
I have:
- a dynamic declaration
- a dynamic ALVGRID to show data
I need to store data into a dictionary table:
loop at <dyn_table> into <DYN_WA>.
insert <DYN_WA> into ( p_tab ). ??????
endloop.
‎2006 Dec 19 2:36 PM
I'm tryng with:
INSERT (p_tab) FROM TABLE <dyn_table>.
It seems to work...
‎2006 Dec 19 2:02 PM
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
Regards,
Amit