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
399

Hi All,

I need to create a dynamic internal table. I will have to decide the number of fields during runtime, take the data in internal table and work on it further. Please suggest.

3 REPLIES 3
Read only

Former Member
0 Likes
372

Hi Priti,

WELCOME TO SDN!!!

please check this link Dynamic Intertnal table

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

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.

Best regards,

raam

Read only

Former Member
0 Likes
372

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.

pls go through this program.

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.

Naresh.

Edited by: Matt on Nov 7, 2008 2:14 PM

Read only

0 Likes
372

hi Naresh,,.

i have a doubt is this internal table specific to ALV.

what if we are not using the ALV display.

Please do not resurrect old threads, unless adding further helpful information

Edited by: Matt on Nov 7, 2008 2:14 PM