Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Creating internal table dynamicaly at runtime

Former Member
0 Kudos

Hi Experts,

I want to create one internal table dynamically without using FIELD SYMBOL concept.

I have main internal table from that i need to take some fields and create one more internal table at runtime. please help me .......please send if u have any logic.

Thanks and

5 REPLIES 5

Former Member
0 Kudos

Hi,

Look at the below links, which will give the example code

http://www.sap-img.com/ab030.htm

http://searchsap.techtarget.com/tip/0,289483,sid21_gci554038,00.html

Regards

Sudheer

Former Member
0 Kudos

Hi,

Please check the link below :

<a href="https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/dynamicInternalTable&">https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/dynamicInternalTable&</a>

Former Member
0 Kudos

Hi Pavan,

if you want to declare internal Tables dynamically you need a field symbol,

why don't you want to use field-symbols ?

DATA: ref_it_md TYPE REF TO data.

FIELD-SYMBOLS: <fs_it_mddata> TYPE ANY TABLE.

FIELD-SYMBOLS: <fs_wa_mddata> TYPE ANY.

parameters: p_tabnm like dd03l-tabname.

CREATE DATA ref_it_md TYPE STANDARD TABLE OF (tabname)

WITH DEFAULT KEY.

ASSIGN ref_it_md->* TO <fs_it_mddata>.

Kind Regards

Henner

Former Member
0 Kudos

Hi,

Please have a look at the method create_dynamic_table of class cl_alv_table_create. Here you can to determine the line type of the internal table dynamically by constructing a field catalog with the dynamically defined fields.

Also you can use the Run time type services RTTS to create strcutures , tables

etc dynamically in programs. The class CL_ABAPTABLEDESCR is used to create dynamic tables in the programs.

Reward if helpful.

Regards,

Harini.S

Former Member
0 Kudos

Hi,

Yes , you can create a Dynamic Internal table .Just chek out this program .

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.

Regards,

Bhaskar