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 tables

Former Member
0 Likes
1,044

Hi

can anybody please provide me information about dynamic internal tables.

regards

Jyothi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,009

Look at the below code

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.

santhosh

9 REPLIES 9
Read only

Former Member
0 Likes
1,010

Look at the below code

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.

santhosh

Read only

0 Likes
1,009

Hi,

Need information about dynamic internal tables, please.

regards

Read only

0 Likes
1,009

Hi

Internal Tables are local tables within a program containing a series of lines having same data type. ABAPTM Open SQL allows single field, range of fields, entire database table or view into an internal table.

In technical terms Internal table is a dynamic sequential dataset in which all records have the same data structure and a key.

A static internal table can be declared in an ABAPTM program initially, when the structure of the internal table is fixed and known to the user.

Dynamic internal table is an extension to internal table concept, used when the number of fields is not known at the design time or until the compile time.

Check this webblog of Dynamic Internal Table

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

Regards

Read only

0 Likes
1,009

I am looking for any documentation kind of stuff.

regards

Read only

0 Likes
1,009

Hi,

Whatever documentation that is available for field symbols and internal tables is enough for dynamic internal tables.

Regards

Read only

0 Likes
1,009

HI,

Thanks, i knew that we can simulate dynamic table using field symbols. i felt if there any specific information about dynamic table.thanks for your kind help.

Regards

Jyothi

Read only

0 Likes
1,009
Read only

Clemenss
Active Contributor
0 Likes
1,009

Hi,

pleas check this link

[dynamic internal tables.|http://www.google.com/search?hl=de&q=dynamicinternaltables&btnG=Google-Search&meta=lr%3Dlang_en]

Regards,

Clemens

Read only

Former Member
0 Likes
1,009

About dynamic internal tables please look at the below links

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

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

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/dynamicInternalTable&

http://www.saptechnical.com/Tips/ABAP/DynamicIntTable.htm

http://www.sapfans.com/forums/viewtopic.php?p=905962&sid=b26a37b0cffa763175b35373f4ca01b5

http://portal.acm.org/citation.cfm?id=50814&dl=

Below is the example for dynamic internal table creation


REPORT abc.

*------------- COMPULSORY
FIELD-SYMBOLS: TYPE ANY TABLE.
FIELD-SYMBOLS: TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: TYPE ANY.
DATA : fldname(50) TYPE c.

*--------------------
PARAMETERS : infty(4) TYPE c OBLIGATORY.
DATA : iname LIKE dd02l-tabname.

START-OF-SELECTION.
*------------------- GET INFO
CONCATENATE 'P' infty INTO iname.
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = iname
TABLES
ddfields = ddfields.
.

*------------- CONSTRUCT FIELD LIST

LOOP AT ddfields.
ls-fieldname = ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.

*-------------- PERFORM

PERFORM mydyntable USING lt.

BREAK-POINT.


*---------------------------------------------------------------
* INDEPENDENT FORM
*---------------------------------------------------------------

FORM mydyntable USING lt TYPE lvc_t_fcat .


*-------------- Create Dyn Table From FC

FIELD-SYMBOLS: TYPE REF TO data.
FIELD-SYMBOLS: .
FIELD-SYMBOLS: TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.


ASSIGN lt_data TO .

CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = 
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.


*------------- Assign Dyn Table To Field Sumbol

ASSIGN ->* TO .
ASSIGN TO .
ASSIGN TO .

ENDFORM. "MYDYNTABLE 

Regards,

Chandru