Google Search - Blog...........

ABAP - Dynamic Internal Table All Fields

REPORT Z_DYNAMIC.

type-pools : abap.

field-symbols: type standard table,
,
.

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-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 .

* Create dynamic work area and assign to FS
create data dy_line like line of .
assign dy_line->* to .

endform.


form get_data.

* Select Data from table.
select * into table
from (p_table).

endform.

form write_out.
* Write out data from table.

loop at into .
do.
assign component sy-index
of structure to .
if sy-subrc ne 0.
exit.
endif.
if sy-index = 1.
write:/ .
else.
write: .
endif.
enddo.
endloop.
endform.



ALSO READ:



No comments:

Post a Comment