‎2008 Apr 25 2:04 PM
HI,
I AM WORKING ON BULDING DYNAMIC INTERNAL TABLE AND I AM USING FIELD SYMBOLS FOR THE SAME AS BELOW:
data:
lr_tab type ref to data.
field-symbols:
<tab> type standard table.
create data lr_tab type table of (IO_TABLE).
assign lr_tab->* to <tab>.
SELECT *
INTO TABLE <tab>
FROM (IO_TABLE)
WHERE ..
DURING create data lr_tab type table of (IO_TABLE).* I AM GETTING THE ERROR THAT 'THE TYPE SPECIFICATION OF TABLE IS INCOMPLETE'..CAN ANY ONE PLZ GUDE ME SOLUTION FOR THIS..
PLZZ HELP ME
‎2008 Apr 25 2:13 PM
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.
‎2008 Apr 25 2:35 PM
hi
This is a very simple tip to create a dynamic internal table, ie. a table not defined until runtime, inside ABAP code.
OK, so it only references an SAP database table, but this should be good enough for most applications.
Code
There are a few declarations to make:
field-symbols: <table> type any.
types: fieldref type ref to data.
data: dyn_table type fieldref.
As for the actual code to generate the table:
create data dyn_table type (SAP Table).
assign dyn_table->* to table.
The table is now a field symbol which can be referenced in the normal way.
check this link it will be helpful
http://www.sap-img.com/ab030.htm
<REMOVED BY MODERATOR>
prasanth
Edited by: Alvaro Tejada Galindo on Apr 25, 2008 12:57 PM
‎2008 Apr 25 5:37 PM
Try with the below code. This should work for you.
FIELD-SYMBOLS: <tab> TYPE STANDARD TABLE.
DATA: new_line TYPE REF TO data.
CREATE DATA new_line TYPE STANDARD TABLE OF (IO_TABLE).
ASSIGN new_line->* TO <tab>.
SELECT *
FROM (IO_TABLE)
INTO TABLE <tab>
WHERE ..
Thanks,
Srinivas
‎2008 Apr 26 3:01 PM
hi ...
report z_dynamic.
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.
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.
&----
----
form write_out .
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.
endform. " write_out
regards,
venkat.
‎2008 May 03 11:06 AM
Hi Mahesh,
Compare with this code......
PARAMETER: tabname type dd02l-TABNAME.
DATA: stru_tab TYPE REF TO data.
FIELD-SYMBOLS <tab> TYPE table.
CREATE DATA stru_tab TYPE TABLE OF (tabname).
ASSIGN stru_tab->* TO <tab>.
Regards,
Achyut
‎2008 Sep 30 1:48 PM