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

reg internal tables

Former Member
0 Likes
923

i want to know the concept of dynamic internal tables.

please explain me step by step in detail with good example.

help ful me alot.

i want to know the concept of dynamic internal tables.

please explain me step by step in detail with good example.

help ful me alot.

6 REPLIES 6
Read only

Former Member
0 Likes
864

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 Web blog of Dynamic Internal Table

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

http://www.saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm

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

Regards,

Santosh

Read only

Former Member
0 Likes
864

Hi,

For explanation check the blog

Check the link

[http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm]

Also check the blog

[https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2071] [original link is broken] [original link is broken] [original link is broken];

and ex:

report z_dynamic.

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.

perform get_data.

perform write_out.

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.

Pls. reward if useful....

Read only

0 Likes
864

data: dy_table type ref to data,

dy_line type ref to data,

xfc type lvc_s_fcat,

ifc type lvc_t_fcat.

iam unable to understand the above declaration

dy_table type ref to data(here data seems....)

that means wt it is referring.pls tell me iam new to oop

Read only

Former Member
0 Likes
864

Dynamic internal tables are the internal tables created at run time not like the normal tables which are created before you start data extraction..

Dynamic internal tables can be created using CL_ALV_TABLE_CREATE class and method CREATE_DYNAMIC_TABLE.

Just fill the field catalog(IT_FIELDCATALOG) in the parameter of method (like you do in normal ALV reports) and it creates a pointer to dynamic data table.

Check this code.

report ytest.

data: lt_fieldcatalog type lvc_t_fcat.

data: ls_fieldcatalog type lvc_s_fcat.

field-symbols: <fs_data> type ref to data.

field-symbols: <fs_1>.

field-symbols: <fs_2> type any table.

field-symbols: <fs_3> type ypoll.

data: lt_data type ref to data.

assign lt_data to <fs_data>.

ls_fieldcatalog-fieldname = 'MANDT'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'POLLID'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'TEAM'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'INITIATOR'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'DESCRIPTION'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'APPROVED'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'INITIATED_DATE'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'END_DATE'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'WINNER'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = lt_fieldcatalog

importing

ep_table = <fs_data>

exceptions

generate_subpool_dir_full = 1

others = 2

.

if sy-subrc 0.

endif.

assign <fs_data>->* to <fs_1>.

assign <fs_1> to <fs_2>.

loop at <fs_2> assigning <fs_3>.

write: <fs_3>-pollid.

endloop.

one more example

.

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.

-


REPORT ZCLUST1 .

  • Example: how to create a dynamic internal table

  • The dynamic internal table stucture

DATA: BEGIN OF STRUCT OCCURS 10,

FILDNAME(8) TYPE C,

ABPTYPE TYPE C,

LENGTH TYPE I,

END OF STRUCT.

  • The dynamic program source table

DATA: BEGIN OF INCTABL OCCURS 10,

LINE(72),

END OF INCTABL.

DATA: LNG TYPE I, TYPESRTING(6).

  • Sample dynamic internal table stucture

STRUCT-FILDNAME = 'field1'. STRUCT-ABPTYPE = 'c'. STRUCT-LENGTH = '6'.

APPEND STRUCT. CLEAR STRUCT.

STRUCT-FILDNAME = 'field2'. STRUCT-ABPTYPE = 'd'.

APPEND STRUCT. CLEAR STRUCT.

STRUCT-FILDNAME = 'field3'. STRUCT-ABPTYPE = 'i'.

APPEND STRUCT. CLEAR STRUCT.

  • Create the dynamic internal table definition in the dyn. program

INCTABL-LINE = 'program zdynpro.'. APPEND INCTABL.

INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.

LOOP AT STRUCT.

INCTABL-LINE = STRUCT-FILDNAME.

LNG = STRLEN( STRUCT-FILDNAME ).

IF NOT STRUCT-LENGTH IS INITIAL .

TYPESRTING(1) = '('.

TYPESRTING+1 = STRUCT-LENGTH.

TYPESRTING+5 = ')'.

CONDENSE TYPESRTING NO-GAPS.

INCTABL-LINE+LNG = TYPESRTING.

ENDIF.

INCTABL-LINE+15 = 'type '.

INCTABL-LINE+21 = STRUCT-ABPTYPE.

INCTABL-LINE+22 = ','.

APPEND INCTABL.

ENDLOOP.

INCTABL-LINE = 'end of dyntab. '.

APPEND INCTABL.

  • Create the code processes the dynamic internal table

INCTABL-LINE = ' '. APPEND INCTABL.

INCTABL-LINE = 'dyntab-field1 = ''aaaaaa''.'. APPEND INCTABL.

INCTABL-LINE = 'dyntab-field1 = ''19970814''.'. APPEND INCTABL.

INCTABL-LINE = 'dyntab-field1 = 1.'. APPEND INCTABL.

INCTABL-LINE = 'append dyntab.'. APPEND INCTABL.

INCTABL-LINE = ' '. APPEND INCTABL.

INCTABL-LINE = 'loop at dyntab.'. APPEND INCTABL.

INCTABL-LINE = 'write: / dyntab.'. APPEND INCTABL.

INCTABL-LINE = 'endloop.'. APPEND INCTABL.

  • Create and run the dynamic program

INSERT REPORT 'zdynpro'(001) FROM INCTABL.

SUBMIT ZDYNPRO.

-


or Just try out this simpler dynamic internal tables

DATA: itab TYPE STANDARD TABLE OF spfli,

wa LIKE LINE OF itab.

DATA: line(72) TYPE c,

list LIKE TABLE OF line(72).

START-OF-SELECTION.

*line = ' CITYFROM CITYTO '.

line = ' AIRPTO '.

APPEND line TO list.

SELECT DISTINCT (list)

INTO CORRESPONDING FIELDS OF TABLE itab

FROM spfli.

IF sy-subrc EQ 0.

LOOP AT itab INTO wa.

  • WRITE: / wa-cityfrom, wa-cityto.

WRITE 😕 wa-airpto.

ENDLOOP.

ENDIF.

also have a look at below weblog:

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

It gives you info abt how to create dynamic internal table.

see this program

Reward points if useful.

Read only

Former Member
0 Likes
864

Reward points..

Read only

Former Member
0 Likes
864

Hi ,

Internal Table

An internal table is a temporary table stored in RAM on the application server. It is created and filled by a program during execution and is discarded when the program ends. Like a database table, an internal table consists of one or more rows with an identical structure, but unlike a database table, it cannot hold data after the program ends. Use it as temporary storage for manipulating data or as a temporary private buffer.

Definition of an Internal Table

An internal table consists of a body and an optional header line .

The body holds the rows of the internal table. All rows within it have the same structure. The term "internal table" itself usually refers to the body of the internal table.

The header line is a field string with the same structure as a row of the body, but it can only hold a single row. It is a buffer used to hold each record before it is added or each record as it is retrieved from the internal table.

To define an internal table body, use occurs n on the definition of any field string except tables. occurs creates the body of the internal table. The memory for the body is not allocated until the first row is added to it. Without occurs, you only have a field string.

To define an internal table with a header line, you must include either begin of or with header line in the definition. A header line is automatically created if begin of appears in the definition. If you use like instead of begin of, the internal table will not have a header line unless you add with header line after the occurs clause. This is illustrated in lines 2 through 10 of Listing 11.1.

The only time you would create an internal table without a header line is in the case of a nested internal table. A nested internal table cannot have a header line.

Listing 11.1 Basic Ways of Defining Internal Tables with and Without a Header Line

1 report ztx1101.

2 data: begin of it1 occurs 10, "has a header line

3 f1,

4 f2,

5 f3,

6 end of it1.

7

8 data it2 like ztxlfa1 occurs 100. "doesn't have a header line

9

10 data it3 like ztxlfa1 occurs 100 with header line. "it does now

Reward if useful

Regards ,

Shankar GJ

Edited by: Shankar GJ on Apr 11, 2008 7:16 AM