2005 Jul 26 7:43 PM
Hi,
i'm searching for a function module which accepts a given db table as input and populates all the records in an internal table. can anyone suggest an idea to do that.
thanks,
ravi.
2005 Jul 26 7:46 PM
Hi Ravi;
Check out this blog, it may point you in the right direction...
/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table
-John
2005 Jul 26 7:46 PM
Hi Ravi;
Check out this blog, it may point you in the right direction...
/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table
-John
2005 Jul 26 8:19 PM
Here is a sample program.
report zrich_0002.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.
* Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
* Select Data from table.
select * into table <dyn_table>
from (p_table).
* 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.
Regards,
Rich Heilman