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

Regarding Dynamic Internal table

Former Member
0 Likes
589

hi guys,

could any one help me in explanining what is dynamic internal table concept in ABAP.

information regarding this is appreciated

thanks very much

pavan

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
477

Sure, I dynamic internal table is one that is built on the fly during runtime as opposed to one that is defined at design time. Usually you define interal tables like this directly in your program.

Types: begin of ttab,
       fld1(10) type c,
       fld2 type sy-datum,
       end of ttab.

data: itab type table of ttab.

You can also build an internal table at runtime.

Here is a sample program.



report zrich_0003
       no standard page heading.

type-pools: slis.

field-symbols: <dyn_table> type standard table,
               <dyn_wa>.

data: alv_fldcat type slis_t_fieldcat_alv,
      it_fldcat type lvc_t_fcat.


selection-screen begin of block b1 with frame title text-001.
parameters: p_check type c.
selection-screen end of block b1.

start-of-selection.

  perform build_dyn_itab.
  perform build_report.

  loop at <dyn_table> into <dyn_wa>.
    write:/ <dyn_wa>.
  endloop.


************************************************************************
*  Build_dyn_itab
************************************************************************
form build_dyn_itab.

  data: index(3) type c.

  data: new_table type ref to data,
        new_line  type ref to data,
        wa_it_fldcat type lvc_s_fcat.

* Create fields
  clear index.
  do 10 times.
    index = sy-index.
    clear wa_it_fldcat.
    concatenate 'Field' index into
             wa_it_fldcat-fieldname .
    condense  wa_it_fldcat-fieldname no-gaps.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-intlen = 5.
    append wa_it_fldcat to it_fldcat .
  enddo.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
               exporting
                  it_fieldcatalog = it_fldcat
               importing
                  ep_table        = new_table.

  assign new_table->* to <dyn_table>.

* Create dynamic work area and assign to FS
  create data new_line like line of <dyn_table>.
  assign new_line->* to <dyn_wa>.

endform.

*********************************************************************
*      Form  build_report
*********************************************************************
form build_report.

  data: fieldname(20) type c.
  data: fieldvalue(5) type c.
  data: index(3) type c.
  field-symbols: <fs1>.

  do 10 times.

    index = sy-index.

* Set up fieldname
    concatenate 'FIELD' index into
             fieldname .
    condense   fieldname  no-gaps.

* Set up fieldvalue
    concatenate 'FLD' index into
             fieldvalue.
    condense   fieldvalue no-gaps.

    assign component  fieldname  of structure <dyn_wa> to <fs1>.
    <fs1> =  fieldvalue.

  enddo.

* Append to the dynamic internal table
  append <dyn_wa> to <dyn_table>.

endform.

Regards,

Rich Heilman

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
478

Sure, I dynamic internal table is one that is built on the fly during runtime as opposed to one that is defined at design time. Usually you define interal tables like this directly in your program.

Types: begin of ttab,
       fld1(10) type c,
       fld2 type sy-datum,
       end of ttab.

data: itab type table of ttab.

You can also build an internal table at runtime.

Here is a sample program.



report zrich_0003
       no standard page heading.

type-pools: slis.

field-symbols: <dyn_table> type standard table,
               <dyn_wa>.

data: alv_fldcat type slis_t_fieldcat_alv,
      it_fldcat type lvc_t_fcat.


selection-screen begin of block b1 with frame title text-001.
parameters: p_check type c.
selection-screen end of block b1.

start-of-selection.

  perform build_dyn_itab.
  perform build_report.

  loop at <dyn_table> into <dyn_wa>.
    write:/ <dyn_wa>.
  endloop.


************************************************************************
*  Build_dyn_itab
************************************************************************
form build_dyn_itab.

  data: index(3) type c.

  data: new_table type ref to data,
        new_line  type ref to data,
        wa_it_fldcat type lvc_s_fcat.

* Create fields
  clear index.
  do 10 times.
    index = sy-index.
    clear wa_it_fldcat.
    concatenate 'Field' index into
             wa_it_fldcat-fieldname .
    condense  wa_it_fldcat-fieldname no-gaps.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-intlen = 5.
    append wa_it_fldcat to it_fldcat .
  enddo.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
               exporting
                  it_fieldcatalog = it_fldcat
               importing
                  ep_table        = new_table.

  assign new_table->* to <dyn_table>.

* Create dynamic work area and assign to FS
  create data new_line like line of <dyn_table>.
  assign new_line->* to <dyn_wa>.

endform.

*********************************************************************
*      Form  build_report
*********************************************************************
form build_report.

  data: fieldname(20) type c.
  data: fieldvalue(5) type c.
  data: index(3) type c.
  field-symbols: <fs1>.

  do 10 times.

    index = sy-index.

* Set up fieldname
    concatenate 'FIELD' index into
             fieldname .
    condense   fieldname  no-gaps.

* Set up fieldvalue
    concatenate 'FLD' index into
             fieldvalue.
    condense   fieldvalue no-gaps.

    assign component  fieldname  of structure <dyn_wa> to <fs1>.
    <fs1> =  fieldvalue.

  enddo.

* Append to the dynamic internal table
  append <dyn_wa> to <dyn_table>.

endform.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
477

Hi pavan,

check these links:

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

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

reward if helpful.

regards,

keerthi.

Read only

Former Member
0 Likes
477

Hi Pavan,

Chech the below link:

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

http://www.sapfans.com/forums/viewtopic.php?p=107594

Hope this will helpful.

Regards,

Bhavana

Read only

Former Member
0 Likes
477

Hi Pavan,

HI

PLEASE GO THROUGH THE LINKS

How to create Dynamic internal table

http://72.14.203.104/search?q=cache:PW0nTfKGW78J:www.sap-img.com/ab030.htmDYNAMICINTERNALTABLEABAP+&hl=en&gl=in&ct=clnk&cd=1

Dynamic Internal Tables

http://www.kabai.com/abaps/z53.htm

Please look at the following weblog.

/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically

Rgds,

Prakash

<b>IF THIS IS USEFUL PLEASE REWARD</b>