‎2008 Jul 24 7:48 AM
this is program from dynamic internal table , i couldn't understand how the author has used oops /methods in it, please explain me this code.
&----
*& Report ZTESTDK3
*&
&----
*&
*&
&----
REPORT ZTESTDK3.
type-pools : abap.
types : begin of itab,
studid(4) type n,
name(10) type c,
address(15) type c,
phoneno(10) type n,
streamid(4) type n,
end of itab.
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.
end-of-selection.
*********************
*********************
*********************
*********************
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.
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 data from table.
‎2008 Jul 24 7:54 AM
1. Input the Table name .
2. Using the table name get the Field names using the class
and methods
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails = ref_table_des->components.
3.
now loop the fields and populate the fieldcatalog
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.
4. Now create the Dynamic table using the fieldcat
using the class cl_alv_table_create
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>.
5.
select the data to dynamic internal table
select * into table <dyn_table>
from (p_table).
endform.
6. write the data to the output
‎2008 Jul 24 7:54 AM
1. Input the Table name .
2. Using the table name get the Field names using the class
and methods
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails = ref_table_des->components.
3.
now loop the fields and populate the fieldcatalog
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.
4. Now create the Dynamic table using the fieldcat
using the class cl_alv_table_create
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>.
5.
select the data to dynamic internal table
select * into table <dyn_table>
from (p_table).
endform.
6. write the data to the output