Application Development and Automation 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: 
Read only

Dynamic Internal Table

Former Member
0 Likes
363

Hi Abapers,

Can anyone plz tell me wat is dynamic internal table with an example to create dynamic internal table?

Thanks in Advance...

Thanks & Regards,

Radhika Dasharatha.

2 REPLIES 2
Read only

Former Member
0 Likes
338

hi

good

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.

go through this link

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

thanks

mrutyun^

Read only

Former Member
0 Likes
338

Dynamic internal table is nothing more than a normal internal ..

But we create it during run time according to our requirements..

You will need to use field-symbols to use dynamic internal tables.

Sample Code is given below...

data: t_fieldcat TYPE lvc_t_fcat,

wa_fieldcat TYPE lvc_s_fcat,

new_table TYPE REF TO data,

new_line TYPE REF TO data.

field-symbols: <t_tab> TYPE STANDARD TABLE,

<wa_str> type any.

wa_fieldcat-fieldname = 'FLD1'.

wa_fieldcat-tabname = 'TAB'.

wa_fieldcat-datatype = 'CHAR'.

wa_fieldcat-inttype = 'C'.

wa_fieldcat-intlen = w_len1. " determine during run time

APPEND wa_fieldcat TO t_fieldcat.

wa_fieldcat-fieldname = 'FLD2'.

wa_fieldcat-tabname = 'TAB'.

wa_fieldcat-datatype = 'CHAR'.

wa_fieldcat-inttype = 'C'.

wa_fieldcat-intlen = w_len2. " determine during run time

APPEND wa_fieldcat TO t_fieldcat.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_fieldcat

IMPORTING

ep_table = new_table.

ASSIGN new_table->* TO <t_tab>.

CREATE DATA new_line LIKE LINE OF <t_tab>.

ASSIGN new_line->* TO <wa_str>.

      • Now <t_tab> is the internal table and <wa_str> is its work area

u can not access the fields of dynamic internal directly..

u will have to use ASSIGN COMPONENT statement for this purpose...

syntax is :

loop at <t_tab> into <wa_str>.

do.

ASSIGN COMPONENT sy-index OF STRUCTURE <wa_str> TO <l_field>

if sy-subrc ne 0.

exit.

endif.

    • Do ur coding for fields..

enddo.

Reward if u find it useful...

tell me if u still need some more..